Windows/WinXP CMD:如何将脚本的输出传递到日志文件并显示输出? [英] Windows/WinXP CMD: How to pipe the output of a script to a log file AND display output?
问题描述
我正在从cmd运行python脚本.我目前正在将脚本的输出传递到我指定的日志文件中.但是,我还希望能够通过观察输出滚动来直观地监视执行进度.
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.
您能提出解决我的问题的更好方法吗?理想情况下,我希望将输出通过管道传输到文件并在执行时以cmd显示.
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.
谢谢!
推荐答案
使用来自cygwin的tee命令...
Use tee command from cygwin...
或者自己很容易实现(至少是基本版本)tee命令.
Or it is very easy to implement (at least basic version) of tee command yourself.
发球区用法:
your_command | tee outfile.txt #overwrites file
your_command | tee -a outfile.txt #overwrites file
要捕获stderr和stdout,请使用
your_command 2>&1 | tee [-a] outfile.txt
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
这篇关于Windows/WinXP CMD:如何将脚本的输出传递到日志文件并显示输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!