3

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"
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574

1 Answers1

3

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.

ilian
  • 25,474
  • 4
  • 117
  • 186