The notebook expression resulting from ...

nb = CreateDocument[ExpressionCell[Defer@Random[], "Input"]];
FrontEndTokenExecute[nb, "EvaluateNotebook"];

does not include the output of Random[] as I might have expected from the FrontEndTokenExecute command. Instead NotebookGet@nb acts as if FrontEndTokenExecute was not evaluated despite its execution in the frontend?

I guess this is due to the separation/communication between the frontend and the kernel but can output from evaluations in a generated notebook be grabbed in a single kernel call?

See answer below:

  • $\begingroup$ I do get a new notebook with a random number in it... $\endgroup$ Nov 4, 2012 at 22:52
  • $\begingroup$ Ron I get the output as well. OS X 10.6.8 with V8.0.4. $\endgroup$ Nov 4, 2012 at 23:42
  • $\begingroup$ @Sjoerd & Mike The random number appears in the generated notebook itself but on my machine the expression NotebookGet@nb returns instead Notebook[{Cell[BoxData[RowBox[{"Random", "[", "]"}]], "Input"]}, WindowSize -> {740, 752}, WindowMargins -> {{350, Automatic}, {Automatic, 50}}, FrontEndVersion -> "8.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (October 5, 2011)", StyleDefinitions -> "Default.nb"]? $\endgroup$ Nov 4, 2012 at 23:51
  • 2
    $\begingroup$ If you execute NotebookGet@nb in separate cell you get you expected output (perhaps confirming your guess?) $\endgroup$
    – kglr
    Nov 5, 2012 at 0:22
  • $\begingroup$ ok I see what you mean. $\endgroup$ Nov 5, 2012 at 5:24

1 Answer 1


It turns out that instead of FrontEndTokenExecute[nb, "EvaluateNotebook"] the seemingly equivalent NotebookEvaluate[nb, InsertResults -> True] does exhibit the expected behaviour which is good as this function seems neater anyway (and has a few more options).

nb = CreateDocument[ExpressionCell[Defer@Random[], "Input"]];
NotebookEvaluate[nb, InsertResults -> True];

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.