如何将 Mathematica 打印和错误打印重定向到文件?

发布于 2025-01-01 00:34:23 字数 268 浏览 2 评论 0原文

如何将 Mathematica 打印和错误打印重定向到文件?

有时,Mathematica 程序

  • 1) 使用 Print[] 打印消息,
  • 2) 有时,某些函数在没有任何显式 Print[] 的情况下会产生副作用类型的打印
  • 3)有时会出现打印错误。

如何将上述三种打印重定向到(单独的)文本文件,以便在 Mathematica 内核关闭时可以(单独)存档它们?

How to redirect Mathematica printing and error printing to files?

Sometimes, a Mathematica program

  • 1) uses Print[] to print messages,
  • 2) sometimes, there is side-effect type of printing by some functions without any explicit Print[]
  • 3) and sometimes there is error printing.

How to redirect the above three varieties of printing to (separate) text files, so they can be archived (separately) when the Mathematica kernel is closed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2025-01-08 00:34:23

Print[] 默认情况下输出到流$Output。消息进入 $Messages 流。您可以重新定义这两个全局变量以将输出重定向到文件:

stream = OpenWrite["out.txt", FormatType -> OutputForm]
$Output = {stream}

Print[] by default outputs to the stream $Output. Messages go to the $Messages stream. You can redefine these two global variables to redirect the output to a file:

stream = OpenWrite["out.txt", FormatType -> OutputForm]
$Output = {stream}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文