Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将unix程序的输出(常规或错误)记录到文件中_Unix - Fatal编程技术网

如何将unix程序的输出(常规或错误)记录到文件中

如何将unix程序的输出(常规或错误)记录到文件中,unix,Unix,如何将Unix程序的输出(常规或错误)记录到文件中?从./program>file.log 2>&1开始 ./program > file.log 2>&1 这将把stdout和stderr重定向到file.log以./program>file.log 2>&1启动它 ./program > file.log 2>&1 这会将stdout和stderr重定向到file.log重定向,就像上面的回答一样,这是非常标准的,但有时您确实希望捕获会话中的所有内容。为此,您可以使用“脚本”

如何将Unix程序的输出(常规或错误)记录到文件中?

从./program>file.log 2>&1开始 ./program > file.log 2>&1 这将把stdout和stderr重定向到file.log

以./program>file.log 2>&1启动它 ./program > file.log 2>&1
这会将stdout和stderr重定向到file.log

重定向,就像上面的回答一样,这是非常标准的,但有时您确实希望捕获会话中的所有内容。为此,您可以使用“脚本”命令

$ script /path/to/output_file [starts a subshell] $ ./program $ exit $ cat /path/to/output_file $script/path/to/output\u文件 [启动子shell] 美元/程序 $exit $cat/path/to/output\u文件
脚本的优点是您不需要担心shell语义,也不需要知道正在运行哪个shell等等。。缺点是它确实捕获了进入终端的所有内容,包括控制代码、删除密钥等。

像上面的答案一样重定向是非常标准的,但有时您确实希望捕获会话中的所有内容。为此,您可以使用“脚本”命令

$ script /path/to/output_file [starts a subshell] $ ./program $ exit $ cat /path/to/output_file $script/path/to/output\u文件 [启动子shell] 美元/程序 $exit $cat/path/to/output\u文件 脚本的优点是您不需要担心shell语义,也不需要知道正在运行哪个shell等等。。缺点是它确实捕获了所有进入终端的信息,包括控制代码、删除键等