shell exec命令执行shell打印输出到一个文件

Posted Oops!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell exec命令执行shell打印输出到一个文件相关的知识,希望对你有一定的参考价值。

[[email protected] ~]# cat 1.sh 
#!/bin/bash

exec 1>> /tmp/2.log 2>>/tmp/2.log
date 
echo 111
ldkkdfkslfds
date
[[email protected] ~]# ./1.sh 
[[email protected] ~]# cat /tmp/2.log 
Sat Jun  9 15:08:19 UTC 2018
111
./1.sh: line 6: ldkkdfkslfds: command not found
Sat Jun  9 15:08:19 UTC 2018
Sat Jun  9 15:10:39 UTC 2018
111
./1.sh: line 6: ldkkdfkslfds: command not found
Sat Jun  9 15:10:39 UTC 2018

 

以上是关于shell exec命令执行shell打印输出到一个文件的主要内容,如果未能解决你的问题,请参考以下文章

协程 shell_exec 如何捕获标准错误流

[go]os/exec执行shell命令

php执行外部命令函数:exec()passthru()system()shell_exec()对比

Python执行 shell 命令并实时打印输出

【exec】shell脚本中的 exec 命令

shell脚本中的 exec 命令