How is it possible to send the whole content of an existing notebook to Mathematica for evaluation by using NetLink/C#?


1 Answer 1


To evaluate a notebook from .NET, a batch file and a package file can be used. This example opens and evaluates a notebook called "run.nb" in the front end. Ref:- https://stackoverflow.com/q/7626491/879601

i.e. batch file:-

@echo off
PATH = C:\Program Files\Wolfram Research\Mathematica\8.0\;%PATH%
start MathKernel -noprompt -initfile "C:\Temp\test.m"

and package file, "test.m":-

nb = NotebookOpen["C:\\Temp\\run.nb"];
SelectionMove[nb, All, Notebook];

The batch file and package file can be created on the fly and run from .NET, (or perhaps you could execute the start command directly and dispense with the batch file).

Alternatively, you could run the main notebook (as a package) in Mathematica script mode. The above answer uses the front end in order to save output cell information.

Your question mentions evaluating an existing notebook, but if you also need to create the notebook in .NET this post may be of use:- https://stackoverflow.com/a/7321479/879601

  • $\begingroup$ Hi. Thank you for your answer. If I understand you correct, there is now possibilty to use .netLink to evaluate an existing notebook?!? Is ist possible to send parameters to the batch file and also return results? Thank you $\endgroup$
    – user6511
    Mar 25, 2013 at 6:17
  • $\begingroup$ @user6511 - the batch file can be created in .NET on the fly. Retrieval of results from the evaluated notebook depends on the notebook writing data somewhere where it can be read back in by a .NET program. Otherwise you can get the notebook to save its output using NotebookSave. $\endgroup$ Mar 25, 2013 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.