Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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

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

A workaround using $PrePrint:

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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