3
$\begingroup$

I'm on under OS X trying to run a script through the kernel. My actual plan is to run a bash script which would call mathematica with an address to process a file. I have finished the code (with precious contributions) and it's working properly. but when I run it in kernel it accepts it but nothing happens! I have settled up kernel (in zsh ~/.zshrc ).

alias math="/Applications/Mathematica.app/Contents/MacOS/MathKernel"

I am using "oh my zsh"

and when I just simply type math kernel runs!

Mathematica 10.2.0 for Mac OS X x86 (64-bit)
Copyright 1988-2015 Wolfram Research, Inc.

In[1]:= 

but when I type

math -script cube_plot.m

nothing happens! (it is supposed to create a jpeg file, I also changed the code to print "something" in case export command doesn't or I dunno??! but still nothing)

I also have another question if I fixed this issue for passing an address to my notebook through script command can I use this

math -script cube_plot.m address="/Users/ray/Desktop/Reza/3-1/CMe2/CMe2-t.spindens.cube"
$\endgroup$
  • $\begingroup$ Did you by any chance create cube_plot.m using the Mathematica frontend? You may be running into (9921). $\endgroup$ – ilian Sep 5 '15 at 23:24
  • $\begingroup$ I still have the second question, how to pass a variable to mathematica script? $\endgroup$ – Raymond Ghaffarian Shirazi Sep 6 '15 at 3:03
  • $\begingroup$ you can try to run the kernel and input your value, then quit, through bash. The variable should be kept there. $\endgroup$ – Sarah Aria Sep 6 '15 at 3:11
3
$\begingroup$

For the first part of the question, the most likely reason is that the script was created by saving a notebook as a .m file from the Mathematica frontend. This causes all code to be commented out, except for initialization cells, as described with more detail in this question. Whether this is the case can be verified by opening the .m file with a text editor and checking its contents.

For the second part, one can use the -run command line option. For example, if the script contains

$ cat test.m
Print["Hello, my name is ", name]

the following tells the kernel to set the value of name in advance

$ math -run "name=\"Bob\"" -script test.m
Hello, my name is Bob

It is also possible to set an environment variable in the shell, and then read its value with GetEnvironment.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.