开发者

Need help understanding a bash command

It's actually a combination of php and bash:

exec(sprintf("%s > %s 2>&1 & echo $! >> %s",开发者_StackOverflow社区 $cmd, $outputfile, $pidfile));

I don't understand what 2>&1 & echo $! is there for?


2>&1 redirects stderr to stdout, and $! "Expands to the process ID of the most recently executed background (asynchronous) command".

So, here's what happens:

  1. You send both stderr and stdout of $cmd to a file named $outputfile. If you didn't do 2>&1, you wouldn't be able to read the stderr output in the file.
  2. The following & means that process runs in the background.
  3. Then you append the PID of $cmd (obtained through $!) to the end of $pidfile.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜