Skip to main content
1 of 3
Ajasja
  • 13.8k
  • 3
  • 47
  • 105

How to Print to the Console

Background:

Using the settings under Edit-> Preferences->Evaluation I can redirect all the Print statments to the console.

Settings dialog

What I'd really like to do is redirect just some specific Print statements to the console. I know I can print to another notebook with something like:

PrintToNotebook[nb_, expr_] := ( 
   SelectionMove[nb, After, Cell]; 
   NotebookWrite[nb, Cell[BoxData[ToBoxes[expr]], "Print"]]) 

So perhaps this boils down to finding the "Console Handle"?

Question: How can I create a function (eg PrintToConsole) that behaves like Print but outputs to the console?

Ajasja
  • 13.8k
  • 3
  • 47
  • 105