Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7138 > unrolled thread

How to run ".nb" file always in dos command line

Started bywch <weichanghe2000@gmail.com>
First post2011-12-12 11:42 +0000
Last post2011-12-15 09:56 +0000
Articles 4 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How to run ".nb" file always in dos command line wch <weichanghe2000@gmail.com> - 2011-12-12 11:42 +0000
    Re: How to run ".nb" file always in dos command line Chris Degnen <degnen@cwgsy.net> - 2011-12-13 10:55 +0000
      Re: How to run ".nb" file always in dos command line A Retey <awnl@gmx-topmail.de> - 2011-12-14 11:10 +0000
      Re: How to run ".nb" file always in dos command line wch <weichanghe2000@gmail.com> - 2011-12-15 09:56 +0000

#7138 — How to run ".nb" file always in dos command line

Fromwch <weichanghe2000@gmail.com>
Date2011-12-12 11:42 +0000
SubjectHow to run ".nb" file always in dos command line
Message-ID<jc4pan$cfa$1@smc.vnet.net>
Hi,everybody,I have met an problem when run mathematica in DOS
interface. I will tell you this confuse:
in "1.nb" file, I have written a sentence: Plot[Sin[x], {x, 0, 6 Pi}],
then I run 1.nb in DOS command line with "> 1.nb", it will be opened
in a moment.
now I want to evaluate "1.nb" in DOS in order to generate the figure
of Plot[Sin[x], {x, 0, 6 Pi}]. but I don't know how to send order to
mathematica.
In a word, I want to execute all process in DOS command not under
notebook interface through "shift + enter". combination.
Thank you for all the information in advance,I am wating for your
coming.

[toc] | [next] | [standalone]


#7187

FromChris Degnen <degnen@cwgsy.net>
Date2011-12-13 10:55 +0000
Message-ID<jc7aui$p27$1@smc.vnet.net>
In reply to#7138
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[]];


Now to open your file from the command line.  I first put
Mathematica on the search path, just for the session (using
setlocal).  So, at the command line type or paste:

setlocal
PATH = C:\Program Files\Wolfram Research\Mathematica\8.0\;%PATH%
mathematica "C:\temp\plot demo\1.nb"

(Your DOS command "> 1.nb" did not work for me, so I used
mathematica "C:\temp\plot demo\1.nb")

Now you can evaluate the notebook with this command:

start MathKernel -noprompt -initfile "C:\temp\plot demo\runplot.m"



In case this is of interest, here are some references where
I have discussed similar applications on StackOverflow:-

Evaluating a notebook from the command line
http://tinyurl.com/evalnotebook

About kernel warning message from UseFrontEnd
http://tinyurl.com/uncaughtthrow

Starting and restarting kernels
http://tinyurl.com/restartkernel


On Dec 12, 11:42 am, wch <weichanghe2...@gmail.com> wrote:
> Hi,everybody,I have met an problem when run mathematica in DOS
> interface. I will tell you this confuse:
> in "1.nb" file, I have written a sentence: Plot[Sin[x], {x, 0, 6 Pi}],
> then I run 1.nb in DOS command line with "> 1.nb", it will be opened
> in a moment.
> now I want to evaluate "1.nb" in DOS in order to generate the figure
> of Plot[Sin[x], {x, 0, 6 Pi}]. but I don't know how to send order to
> mathematica.
> In a word, I want to execute all process in DOS command not under
> notebook interface through "shift + enter". combination.
> Thank you for all the information in advance,I am wating for your
> coming.

[toc] | [prev] | [next] | [standalone]


#7207

FromA Retey <awnl@gmx-topmail.de>
Date2011-12-14 11:10 +0000
Message-ID<jca07d$a3q$1@smc.vnet.net>
In reply to#7187
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

[toc] | [prev] | [next] | [standalone]


#7223

Fromwch <weichanghe2000@gmail.com>
Date2011-12-15 09:56 +0000
Message-ID<jccg92$mft$1@smc.vnet.net>
In reply to#7187
On 12=D4=C213=C8=D5, =CF=C2=CE=E76=CA=B155=B7=D6, Chris Degnen <deg...@cwgsy.net> wrote:
> 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[]];
>
> Now to open your file from the command line.  I first put
> Mathematica on the search path, just for the session (using
> setlocal).  So, at the command line type or paste:
>
> setlocal
> PATH = C:\Program Files\Wolfram Research\Mathematica\8.0\;%PATH%
> mathematica "C:\temp\plot demo\1.nb"
>
> (Your DOS command "> 1.nb" did not work for me, so I used
> mathematica "C:\temp\plot demo\1.nb")
>
> Now you can evaluate the notebook with this command:
>
> start MathKernel -noprompt -initfile "C:\temp\plot demo\runplot.m"
>
> In case this is of interest, here are some references where
> I have discussed similar applications on StackOverflow:-
>
> Evaluating a notebook from the command linehttp://tinyurl.com/evalnotebook
>
> About kernel warning message from UseFrontEndhttp://tinyurl.com/uncaughtthrow
>
> Starting and restarting kernelshttp://tinyurl.com/restartkernel
>
> On Dec 12, 11:42 am, wch <weichanghe2...@gmail.com> wrote:
>
>
>
> > Hi,everybody,I have met an problem when run mathematica in DOS
> > interface. I will tell you this confuse:
> > in "1.nb" file, I have written a sentence: Plot[Sin[x], {x, 0, 6 Pi}],
> > then I run 1.nb in DOS command line with "> 1.nb", it will be opened
> > in a moment.
> > now I want to evaluate "1.nb" in DOS in order to generate the figure
> > of Plot[Sin[x], {x, 0, 6 Pi}]. but I don't know how to send order to
> > mathematica.
> > In a word, I want to execute all process in DOS command not under
> > notebook interface through "shift + enter". combination.
> > Thank you for all the information in advance,I am wating for your
> > coming.- =D2=FE=B2=D8=B1=BB=D2=FD=D3=C3=CE=C4=D7=D6 -
>
> - =CF=D4=CA=BE=D2=FD=D3=C3=B5=C4=CE=C4=D7=D6 -

thank you very much. it is wonderful, it almost satisfying my desire,
but there are some questions I don't understand:
I can run 1.nb and generate the figure now, but how to accomplish
saving the generated plot and exit 1.nb these a series of process
through DOS command?
I am looking forward to your reply.
thanks !

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web