开发者

Exporting Mathematica Print[] Output to a .txt file

开发者 https://www.devze.com 2023-04-12 18:08 出处:网络
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 this notebook generates. Is there any w

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 this notebook generates. Is there any way I can automate the expo开发者_JS百科rt of this output to a .txt file without having to re-write the Print[] commands?


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.


You want the PutAppend command.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号