3
$\begingroup$

Starting with a notebook CDoc.nb that contains one input cell:

CreateDocument["\ttest"]

If I evaluate this in the open notebook, it makes a new window. However, from shell command line:

mathematica -ne CDoc.nb

it doesn't make a new window, merely returns. What's the best way to evaluate such a notebook from shell command line in a way that CreateDocument works?

$\endgroup$
4
  • $\begingroup$ Hi, I think it needs a frontend to open a document. mathematica in the shell only starts a kernel. $\endgroup$ Dec 29, 2020 at 16:48
  • $\begingroup$ @DanielHuber Without the -ne, mathematica opens the notebook in the front end (but doesn't execute it). $\endgroup$
    – John Doty
    Dec 29, 2020 at 18:18
  • $\begingroup$ Are you trying to create a new notebook, execute an existing notebook, or open an existing notebook? $\endgroup$ Dec 29, 2020 at 18:45
  • 2
    $\begingroup$ @RudyPotter I'm executing an existing notebook that contains code to create another notebook on the screen. $\endgroup$
    – John Doty
    Dec 29, 2020 at 18:58

1 Answer 1

4
$\begingroup$

I got it to work with the command line:

 Mathematica "C:\*my path*\CDoc.nb"

But first I had to do the following:

  1. Open CDoc.nb
  2. Select the input cells you want to execute on open and then select from the main menu: Cell > Cell Properties > Initialization Cell (Or press Ctrl+8)
  3. Open the Option Inspector by pressing Shift_Ctrl+O or by selecting from the main menu Format > Option Inspector
  4. In Option Inspector, select Global Preferences from the top pulldown menu then navigate to Notebook Options > Evaluation Options on the left hand tree menu and uncheck "GlobalInitializationCellWarning"
  5. On top pulldown menu change Global Preferences to CDoc.nb and navigate to Notebook Options > Evaluation Options on the left hand tree menu and set "InitializationCellEvaluation" to True and set "InitializationCallWarning" to False
  6. Save CDoc.nb
  7. Close Mathematica
  8. Open command line window and navigate to your Mathematica directory:
    For example: cd C:\Program Files\Wolfram Research\Mathematica\12.1
  9. Enter Mathematica "C:\*your path*\CDoc.nb"
$\endgroup$
3
  • 1
    $\begingroup$ This works. It has the unfortunate side effect that every notebook I open with initialization cells runs them whether I want to run them or not. $\endgroup$
    – John Doty
    Dec 29, 2020 at 21:54
  • $\begingroup$ @JohnDoty Well, only notebooks where someone has set "InitializationCellEvaluation" to True and set "InitializationCallWarning" to False. You could turn "GlobalInitializationCellWarning" back on when you are done with your project and are messing with sketchy files. $\endgroup$ Dec 29, 2020 at 22:07
  • 2
    $\begingroup$ Ah, yes, keeping track of global versus notebook options. Annoyingly difficult in the confusing preferences dialog on a teensy Raspberry Pi touchscreen. But I got it, it's all working. Thanks! $\endgroup$
    – John Doty
    Dec 30, 2020 at 1:33

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.