tags:

views:

41

answers:

1

It's actually a combination of php and bash:

exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));

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

+5  A: 

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.
Mark Rushakoff
So you mean it actually runs two commands within a line?
Yes it does: `$cmd` and `echo`
mouviciel