[Date Index]
[Thread Index]
[Author Index]
Re: Executing a Notebook and saving the modified Notebook - all without the GUI
*To*: mathgroup at smc.vnet.net
*Subject*: [mg125151] Re: Executing a Notebook and saving the modified Notebook - all without the GUI
*From*: John Fultz <jfultz at wolfram.com>
*Date*: Sat, 25 Feb 2012 01:52:34 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Reply-to*: jfultz at wolfram.com
NotebookEvaluate with the InsertResults->True option would be an ideal solution,
except that it doesn't presently work from a standalone kernel. I might be able
to come up with some Mathematica code which would fix (mostly) the problem in
8.0.4 if there's interest (yes, we're fixing this problem in a future release).
Let me know. I'm afraid it's very unlikely that I could come up with a fix that
would affect earlier versions.
It does work perfectly when evaluated from within a front end.
A note about NotebookEvaluate...even when run in a standalone kernel, it
requires the ability to run an FE with UsingFrontEnd[], and therefore a
windowing system to run against. This means that it can't be used from a Linux
command line without an X server or a Windows/Mac box that is not logged into a
user account.
Sincerely,
John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.
On Fri, 24 Feb 2012 00:57:35 -0500 (EST), Arturas Acus wrote:
> Dear Mundi
>
> Probably not exactly what you want, but may be you can use something
> from below.
>
> First of all to run graphical Mathematica programs like Plot from
> command line you need to run vnc server
>
> vncserver :1
>
> Then You can use JLink in the following way
>
> ----------------- put into somefile.m --------------
>
> whereIam = "/home/acus/";
> $Path = Append[$Path, whereIam];
> SetDirectory[whereIam];
>
> Needs["JLink`"];
> $FrontEndLaunchCommand = "mathematica -mathlink -display :1 -nogui";
> arprisijungiau = ConnectToFrontEnd[];
> Put[arprisijungiau, "testNon.txt"]
>
> tempNotebookName = "test1.nb";
> grMain1 = UseFrontEnd[Plot[Sin[x], {x, 0, Pi}]];
>
> If[tempNotebookName =!= "EvaluationNotebook[]", If[
> (tmpNb = NotebookOpen[ToFileName[whereIam, tempNotebookName]]
> ) === $Failed, SetDirectory[whereIam];
> tmpNb = CreateDocument[]; NotebookSave[tmpNb, tempNotebookName];
> SelectionMove[tmpNb, After, Notebook];
> NotebookWrite[tmpNb,
> CellGroupData[
> Prepend[(Cell[{ToBoxes[#]}] & /@
> {grMain1, grErr1, grStep1,
> rezults}),
> Cell["Parameters {\[Lambda],\[Mu],g,a}: " <>
> ToString[
> Evaluate[
> NumberForm[#, {3, 4}] & /@ N[{\[Lambda], \[Mu], ggg, aa}]]]=
> ,
> "Subsection"]], Open]];
> NotebookSave[tmpNb];
> PutAppend[tempNotebookName];
> PutAppend[rezults, tempNotebookName];
> NotebookClose[tmpNb, Interactive -> False];,
> CellPrint /@ {grMain1, grErr1, grStep1}]]
>
>
> ------------------------------------------
>
>
> Then simply:
>
> math < ./somefile.m > outIfYouWant.txt
>
>
> So, you need:
> 1. vnc server
> 2. configure to connect front end using JLink.
> 3. To use UseFrontEnd[] for graphical commands and
> 4. properly print cells for nice output to the notebook your are working
> with.
>
> Of course, "simple" is not so simple.
>
>
> Sincerely, Arturas Acus
>
>
> Kt, 2012 02 23 05:46 -0500, C. Mundi ra=F0=EB:
>> 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!
Prev by Date:
**Re: Open nbs automatically with 150%**
Next by Date:
**Re: Executing a Notebook and saving the modified Notebook - all without the GUI**
Previous by thread:
**Re: Executing a Notebook and saving the modified Notebook - all without the GUI**
Next by thread:
**Re: Executing a Notebook and saving the modified Notebook - all without the GUI**
| |