存储 GNU 时间命令和脚本的输出

Storing output of GNU time command and script

我正在尝试 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

当我 运行 如下所示时,(自然地)我没有在终端上看到输出,但是我得到了正确的输出(即脚本的输出后跟 memory/timing开销)。

(/usr/bin/time -f '%P %M %E %S %U' python Script.py arg1 arg2) &> Script.output

有没有办法将tee合并到这里?我更希望看到它的进展,因为这个脚本可能需要一两天才能完成 运行.

time命令将其输出写入stderr,以免污染正在计时的进程stdout

请注意,在您的第二个示例中,您将 stdoutstderr 都重定向为 &>

如果您还想将 stderr 传送到 tee,请使用 |&:

(/usr/bin/time -f '%P %M %E %S %U' python Script.py arg1 arg2) |& tee Script.output