Exporting Mathematica Print[] Output to a .txt file

前端 未结 2 929
谎友^
谎友^ 2020-12-30 03:04

I have a large Mathematica notebook that uses Print[] commands periodically to output runtime messages. This is the only output (aside from exported files) that

相关标签:
2条回答
  • 2020-12-30 03:23

    According to the documentation, Print outputs to the $Output channel which is a list of streams. So, at the beginning of the notebook,

    strm = OpenWrite["output.log"];
    AppendTo[ $Output, strm ];
    

    and at the end of the notebook

    Close[strm];
    

    Note, if execution is interrupted prior to closing the stream, then you'll have to do it manually. Also, the above code will overwrite prior data in "output.log," so you may wish to use OpenAppend, instead.

    Edit: to guarantee that Abort will be called, consider using one of the techniques outlined here.

    0 讨论(0)
  • 2020-12-30 03:42

    You want the PutAppend command.

    0 讨论(0)
提交回复
热议问题