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?
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?
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:
$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.&
means that process runs in the background.$cmd
(obtained through $!
) to the end of $pidfile
.