Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将控制台的输出连续写入文件,输出可能来自两个或多个程序。连续我的意思是,一旦我运行所需的命令或代码,我应该能够在该文件中查看该机器上运行的任何程序的所有标准输出。
只需重定向stdout到该文件,如
stdout
command > file_name
您可以通过以下代码启动 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 ...