0

如何将控制台的输出连续写入文件,输出可能来自两个或多个程序。连续我的意思是,一旦我运行所需的命令或代码,我应该能够在该文件中查看该机器上运行的任何程序的所有标准输出。

4

2 回答 2

2

只需重定向stdout到该文件,如

command > file_name
于 2013-06-06T07:25:37.123 回答
1

您可以通过以下代码启动 bash 脚本:

#!/bin/bash

exec 2> /tmp/outfile.log  # send stderr from your script to a log file
exec 1>&2                      # send stdout to the same log file
set -x
# the rest of your code ...
于 2013-06-06T07:34:05.450 回答