我尝试在终端中运行一个应具有以下功能的命令:
1) 只输出PID,无需等待执行
2) 将日志 stdout 、 stderr 保存在文件中
我尝试过这个:
echo $! | php test.php | tee log.txt &2>&1 /dev/null
但它在终端上的输出中返回我的 stdout 和 stderr。那么不幸的是我们必须等待执行-.-
有人可以帮助我如何构建命令吗?
最佳答案
你可以使用
(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
关于linux - 终端linux (Centos6) : how to exec command -> get PID in output + log file + without waiting?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54206949/