title: Execute program in background, AND capture return code (php & windows)
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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)</p>
  
  <p>I can use <code>exec("start my.exe");</code> and catch the STDOUT, but I can't get the return code (and also not know when it's finished)</p>
  
  <p>I've thought of doing it via a batch file <code>exec(start my.bat);</code> and in the batch file catch the return code, but my command line has dynamic options, so I'd quite to do something like;<br>
  <code>exec("start cmd \"echo hello\");</code></p>
  
  <p>Edit: <s>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.</s><br>
  <code>cmd /C "echo hello"</code> is the solution to this</p>
  
  <p>Doesn't need to be cross-platform, strictly windows (xp-7)</p>