linux - 终端linux (Centos6) : how to exec command -> get PID in output + log file + without waiting?

标签 linux terminal centos stdout stderr

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

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/

相关文章:

linux - 使用命令行参数Bash更改文件名

用于 Linux 的 XML 到 XSD 工具

java - 从终端运行java程序

file - 如何创建像日志文件一样的文件,当更新此日志文件时,副本文件也会更新?

linux - 打印文件中指定数量的行,直到到达末尾

linux - erlang中分布式系统之间的通信

xml - 解析 xml 的 shell 命令运行不正常

Linux - 如何将命令的输出复制到剪贴板

linux - 无法通过 SSH 连接到远程服务器。错误: ssh_exchange_identification: read: Connection reset by peer

centos - cloudera-manager-agent.rpm : does not update installed package error