MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Running notebook from command line

  • To: mathgroup at
  • Subject: [mg121260] Re: Running notebook from command line
  • From: james rund <janjunis at>
  • Date: Tue, 6 Sep 2011 03:58:40 -0400 (EDT)
  • Delivered-to:
  • References: <iuj5ch$npe$>
  • Reply-to: comp.soft-sys.math.mathematica at

I was wondering the same, and it was tedious to find out:
It took me 6 hours ....

there a at least two hurdles, depending what you want to do:

write your code into one cell and make this cell an initialisation cell.
the last entry should be Exit[];
then save your notebook.
now save another version of your notebook as *.m file

this file you can call via command line:
I use:
math -run "<<script.m"

(this is described elsewhere, I assume you have linux or OS X)

math points to the mathematica kernel, for OS X you have to create this alias. this is described elsewhere

If you use any command that requires a front end, then you will see an error message when you run this line from terminal because the Kernel does not have a front end for these functions.

in that case put this line/command in an enclosing
UsingFrontEnd[   your statement goes here   ];

This will start a fronted if required, and your code executes as in the front end / notebook version.

good luck!


  • Prev by Date: Re: Print bug with -script? (quotes display)
  • Next by Date: Re: Quit versus Clear["Global`*"]
  • Previous by thread: Maximum likelihood estimatior
  • Next by thread: How to generate report with Mathematica script from command line (no front end)