6
$\begingroup$

How to write output to an external text file in addition to the standard output stream, i.e. a notebook for a session with FE and stdout for command-line session?

$\endgroup$
6
$\begingroup$

I expected this to work but it apparently only writes Print output:

AppendTo[
  $Output, 
  OpenWrite["out.txt", FormatType -> OutputForm]
]

A workaround using $PrePrint:

output = OpenWrite["out.txt", FormatType -> OutputForm];

$PrePrint = (Write[output, #]; #) &;
$\endgroup$
  • $\begingroup$ Is it possible to use PutAppend[] and not OpenWrite[]? $\endgroup$ – qazwsx Jun 20 '12 at 3:12
  • 1
    $\begingroup$ @MaThEmAtika how about OpenAppend? $\endgroup$ – Mr.Wizard Jun 20 '12 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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