2
它实际上是PHP和bash的组合:需要帮助理解bash命令
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
我不明白是什么2>&1 & echo $!
是那里?
它实际上是PHP和bash的组合:需要帮助理解bash命令
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
我不明白是什么2>&1 & echo $!
是那里?
2>&1
redirects stderr to stdout,并$!
"Expands to the process ID of the most recently executed background (asynchronous) command".
所以,这里是发生了什么:
$cmd
发送到一个名为$outputfile
文件。如果您没有执行2>&1
,则无法读取文件中的stderr输出。&
表示进程runs in the background。$cmd
的PID(通过$!
获得)附加到$pidfile
的末尾。
所以你的意思是它实际上在一行内运行两个命令? – user198729 2010-03-12 12:28:32
是的,它包含:'$ cmd'和'echo' – mouviciel 2010-03-12 12:39:44