Re: How to run ".nb" file always in dos command line
- To: mathgroup at smc.vnet.net
- Subject: [mg123655] Re: How to run ".nb" file always in dos command line
- From: A Retey <awnl at gmx-topmail.de>
- Date: Wed, 14 Dec 2011 06:03:01 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jc4pan$cfa$1@smc.vnet.net> <jc7aui$p27$1@smc.vnet.net>
Hi,
> You can evaluate your notebook from the command line with a
> procedure such as this.
>
> Assuming your working directory is C:\temp\plot demo
>
> create a text file C:\temp\plot demo\runplot.m containing this:
>
>
> Needs["JLink`"];
> $FrontEndLaunchCommand = "Mathematica.exe";
> UseFrontEnd[
> selected = Select[Notebooks[],
> CurrentValue[#, NotebookFileName] === "1.nb"&];
> If[selected != {},
> targetnotebook = First@selected;
> SelectionMove[targetnotebook, All, Notebook];
> SelectionEvaluate[targetnotebook];
> ];
> Exit[]];
While I think the above should work, for version 8 it probably can be
achieved somewhat simpler with something along these lines:
UsingFrontEnd[
NotebookEvaluate[NotebookOpen["full/path/to/file.nb"]]
]
UsingFrontEnd was new in version 7 and seems to replace UseFrontEnd from
the JLink-Package without the need to explicitly load a package and
NotebookEvaluate is new in version 8 and has some additional options
with which one can control the details of the evaluation. See the
documentation for the three functions for more information...
hth,
albert