I'd like to start writing some unit tests for my Mathematica programs and control everything from the command line with some Makefiles.
It seems like Mathematica can be run from the command line but I can't see any basic instructions on getting started with doing this on Mac OS X — has anyone done this before?
Update:
Creating a test file like this:
Print["hello"]; x := 1; y = x+1; z = y+1; Print["y="ToString@y]; Print["z="ToString@z]; Quit[];
And running it with
/Applications/Mathematica.app/Contents/MacOS/MathKernel -noprompt < test.m
is the closest I can get to some sort of batch processing. The output looks ugly, though; newlines are added for every line of the script!
"hello" "y=2" "z=3"
Is this the closest thing I can get to a script that can still output information to the console output? I'm only using Mathematica 6, but I hope that doesn't make a difference.
This, finally, gives output like I'd expect it to:
/Applications/Mathematica.app/Contents/MacOS/MathKernel -noprompt -run "<<test.m"
Makes sense, I suppose. Adding this to my .bash_profile
allows easy execution (as in mma test.m
):
mma () { /Applications/Mathematica.app/Contents/MacOS/MathKernel -noprompt -run "<<$1" ; }
See also dreeves's mash
Perl script, which may offer advantages over this approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With