Windows/WinXP CMD:如何将脚本的输出通过管道传输到日志文件并显示输出?
我正在从 cmd 运行 python 脚本。我当前正在将脚本的输出通过管道传输到我指定的日志文件。但是,我还希望能够通过观察输出滚动来直观地监控执行进度。
我正在通过管道传输到日志文件,因为窗口缓冲区的长度不足以包含整个日志。然而,获得当前执行状态的即时反馈的唯一方法是通过打开日志文件来不断刷新它。
你能建议一个更好的方法来解决我的问题吗?理想情况下,我想将输出通过管道传输到文件并在执行时在 cmd 中显示。
谢谢!
I'm running python scripts from cmd. I am currently piping the output of the script to a log file that I specify. However, I would also like to be able to visually monitor the progress of the execution by watching output scroll.
I'm piping to a log file because the window buffer is not sufficiently long to contain the entire log. However, the only way to get instant feedback of the current state of the execution is to keep refreshing the log file by opening it.
Can you suggest a better way to solve my problem? Ideally I'd like to pipe output to a file and display in cmd while it executes.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 cygwin 中的 tee 命令...
或者自己实现 tee 命令(至少是基本版本)非常容易。
三通用途:
你的命令 | tee outfile.txt #覆盖文件
你的命令 | tee -a outfile.txt #覆盖文件
要捕获 stderr 以及 stdout,请使用
your_command 2>&1 | tee [-a] outfile.txt
Use tee command from cygwin...
Or it is very easy to implement (at least basic version) of tee command yourself.
tee usage:
your_command | tee outfile.txt #overwrites file
your_command | tee -a outfile.txt #overwrites file
To capture stderr as well as stdout, use
your_command 2>&1 | tee [-a] outfile.txt
我建议使用一些带有自动刷新选项的文件查看器。看看来自 superuser.com 的问题:
支持自动刷新的文本/日志编辑器
Windows 上的日志查看器
I would suggest some file viewer with autorefreshing option. Have a look at this questions from superuser.com:
Text / log editor with auto-refresh support
Log viewer on Windows