【问题标题】:terminal linux (Centos6) : how to exec command -> get PID in output + log file + without waiting?终端linux(Centos6):如何执行命令->在输出+日志文件+中获取PID而不等待?
【发布时间】:2019-06-09 22:37:28
【问题描述】:

我尝试在终端中运行一个应该具有这些功能的命令:

1) 仅输出 PID,无需等待执行

2) 将日志 stdout 、 stderr 保存在一个文件中

我试过这个:

echo $! | php test.php | tee log.txt &2>&1 /dev/null

但它会在终端的输出中返回我的标准输出和标准错误。那么不幸的是我们必须等待执行-.-

有人可以帮助我如何构建命令吗?

【问题讨论】:

标签: linux terminal centos stdout stderr


【解决方案1】:

你可以使用

(echo $! | php test.php | tee log.txt &2>&1 /dev/null) &

或者

 nohup (echo $! | php test.php | tee log.txt &2>&1 /dev/null) &

nohup 运行一个不受挂断影响的命令,输出到非 tty

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    相关资源
    最近更新 更多