我正在尝试tee
Python 脚本的输出,以便我可以观察其进度并记录其输出。不过,我还预先添加了 /usr/bin/time
命令,以便我也可以测量内存开销和计时。
当我按如下方式运行命令时,我只看到 Python 脚本的输出,而不是 /usr/bin/time
命令的输出。
(/usr/bin/time -f '%P %M %E %S %U' python Script.py arg1 arg2) | tee Script.output
当我按如下方式运行它时,(自然)我在终端上看不到输出,但是我得到了正确的输出(即脚本的输出,后面跟着内存/计时开销)。
(/usr/bin/time -f '%P %M %E %S %U' python Script.py arg1 arg2) &> Script.output
有没有办法在这里合并tee
?我更希望看到它的进展,因为这个脚本可能需要一两天才能运行。
最佳答案
time
命令将其输出写入 stderr
,以免污染正在计时的进程的 stdout
。
请注意,在第二个示例中,您使用 &>
重定向 stdout
和 stderr
。
如果您还想将 stderr
通过管道传输到 tee
,请使用 |&
:
(/usr/bin/time -f '%P %M %E %S %U' python Script.py arg1 arg2) |& tee Script.output
关于python - 存储 GNU 时间命令和脚本的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54028251/