Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 3 down vote accepted

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, #]; #) &;
share|improve this answer
    
Is it possible to use PutAppend[] and not OpenWrite[]? –  Problemaniac Jun 20 '12 at 3:12
1  
@MaThEmAtika how about OpenAppend? –  Mr.Wizard Jun 20 '12 at 3:47
add comment

Your Answer

 
discard

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.