The question is, how can I run a .nb
file in the kernel mode of Mathematica? I am not an expert in Mathematica, but one of our users who use this program says that in the GUI mode, he selects all the cells (CTRL+A) and then evaluates the notebook (SHIFT+ENTER). However, he wants to run the program in background.
When I test with math < file.nb
, the program quickly exits; however, in the GUI mode, the run time is very large actually.
I read other documentation articles about that, but since I am not expert in Mathmatica, I have no idea!
As an example, solve.nb file is an input to the command math -run < solve.nb
. The output is also available here.
I have no idea what the output means :|
I simply tried to port the solution to Linux. So I wrote a solve.m
file containing
NotebookPauseForEvaluation[nb_] := Module[{},
While[NotebookEvaluatingQ[nb],Pause[1]]];
NotebookEvaluatingQ[nb_]:=Module[{},
SelectionMove[nb,All,Notebook];
Or@@Map["Evaluating"/.#&,Developer`CellInformation[nb]]
];
UsingFrontEnd[
nb = NotebookOpen["/home/mahmood/solve.nb"];
SelectionMove[nb, All, Notebook];
SelectionEvaluate[nb]
NotebookPauseForEvaluation[nb];
NotebookSave[nb];
];
Quit[];
Here is the output of what I see
mahmood@cluster:~$ MathKernel -noprompt -initfile solve.m
mahmood@cluster:~$
LinkConnect::linkc: -- Message text not found -- (LinkObject[7wkjs_shm, 3, 1])
^C
mahmood@cluster:~$
Note that I pressec ^c after several minutes. Also, the is no output file containing th results.
I tried the solution as given by selecting the cells, initialize them and then save the file as .m
. I did that on a GUI machine. The saved script file contains
(* ::Package:: *)
a = 3;
Solve[x^2 + a*x + 1 == 0, x]
As you can see, the last line in the notebook file is not there in the script file. I ran the command and saw
mahmood@cluster:~$ /apps/Mathematica/10.3/SystemFiles/Kernel/Binaries/Linux-x86-64/MathematicaScript -script solve3.m
mahmood@cluster:~$
Is that all? There is no output file containing the result
Comments
Post a Comment