Executing a Notebook and saving the modified Notebook - all without the GUI

*To*: mathgroup at smc.vnet.net*Subject*: [mg125129] Executing a Notebook and saving the modified Notebook - all without the GUI*From*: "C. Mundi" <cmundi at gmail.com>*Date*: Thu, 23 Feb 2012 05:46:23 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

Surely there is a "simple" way to tell Mathematica from the command line to run a notebook and save the state of the notebook! We would have hoped for something like "mathematica.exe --nogui --notebook Test.nb" would work, especially if we embedded something like "NotebookSave[]; End[];" at the end of the file. We've been searching for an answer to this question for days, and none of the answers we've found actually solves our problem. So before you answer, please read my question, which I will try to make very clear with a very simple example at the risk of seeming pedantic. Given a Notebook file, Test.nb with a single cell In[1]:= Plot[Cos[x], {x, 0, 2 Pi}] we can open the Notebook in the front end, Evaluate the (whole) Notebook and get the expected Out which is a plot of a single cycle. We now save the notebook, using the GUI menus. We then open Test.nb in the front end and we see both the input expression and the output plot saved previously. Good. Now we want to do everything *without* the GUI. Let our INPUT be the original Test.nb file, i.e. inputs but no outputs yet. Let our RESULT be a modified Test.nb including the plot. We seek a sequence of batch- like commands which will transform our INPUT into our RESULT, viz. with no GUI interaction and in fact under the control of an external unix shell script. It is permissible for the script to cause mathematica to access files besides Test.nb. We need the output to be in NB form, because we need the embedded graphics. But we also need to evaluate the notebook in an automated, unattended way. At this time, solutions based on MathLink are not attractive to us. We have looked at FrontEndToken but have not yet found a way to effect the result we seek. We also note that some of the interesting FrontEndTokens -- particularly those related to Evaluate -- come with warnings that they are not yet fully integrated into the long-term plan for Mathematica. That sounds ominous. Gracias!