title: Redirecting STDERR in PHP exec
body: <p>I'm writing a PHP script that needs to make some calls to external command line utilities, which I am using exec() for. Had it all working fine locally, but when I moved it over to a live server it no longer works.</p>
  
  <p>After some debugging I believe the problem is down to the STDERR redirection - if I attempt anything to do with redirection (redirect to STDIN, redirect to file) the command completely fails.</p>
  
  <p>I wrote a simple bat script to simplify the test:</p>
  
  <pre><code>@echo off
  echo STDOUT test
  echo STDERR test 1&gt;&amp;2
  </code></pre>
  
  <p>And then in PHP:</p>
  
  <pre><code>&lt;?php
  $cmd = "_test.bat 2&gt;&amp;1";
  exec($cmd, $output, $status);
  var_dump($output);
  var_dump($status);
  ?&gt;
  </code></pre>
  
  <p>On the local server the result is $status=0, $output=array("STDOUT test", "STDERR test") as I would expect, but on the live server the result is $status=1, and output is an empty array!</p>
  
  <p>If I remove the 1>&amp;2 part, I get the same result for both (just the STDOUT part), so the command itself is clearly working as expected.</p>
  
  <p>Is there something simple I am missing here? If it helps, the server is running Windows Server 2008 R2.</p>