I'm writing a couple of PHP scripts to execute a program, capture it's STDOUT and capture the return code when it finishes. These programs could return instantly, or finish in 20 mins, so I need to monitor when they finish.
I can't find a way to start a program in the background and capture the return code [to an external log file]. If I simply use exec, or proc_open, my php script will block, which is no good when the process takes 20 mins.
Even if I can't capture the return code, I need to know when the process has finished. (I can put error codes in the STDOUT instead)
I can use exec("start my.exe");
and catch the STDOUT, but I can't get the return code (and also not know when it's finished)
I've thought of doing it via a batch file exec(start my.bat);
and in the batch file catch the return code, but my command line has dynamic options, so I'd quite to do something like;
exec("start cmd \"echo hello\");
Edit: But I've not found a way to dynamically make a batch-command list on the command line. If anyone knows an approach I'd be very grateful.
cmd /C "echo hello"
is the solution to this
Doesn't need to be cross-platform, strictly windows (xp-7)