title: How to capture multi-line output for commands issued with PHP exec?
body: <p>I am trying to execute system commands in PHP and capture the output of those commands where that output covers multiple lines.  I am using exec(), but it seems like it only returns a value for commands that generate output on a single line.</p>
  
  <p>For example, if I run date at the command line I get:</p>
  
  <pre><code> Wed May 15 15:07:32 EST 2013
  </code></pre>
  
  <p>As expected, if I run this command from PHP as an exec using this...</p>
  
  <pre><code>exec("date",  $exec_results);
  </code></pre>
  
  <p>...then the value of $exec_results becomes...</p>
  
  <pre><code>Array ( [0] =&gt; Wed May 15 15:07:32 EST 2013 )
  </code></pre>
  
  <p>However, when I run time from the command line I get this...</p>
  
  <pre><code>real 0m0.000s
  user 0m0.000s
  sys  0m0.000s
  </code></pre>
  
  <p>...but when I do it from PHP with this...</p>
  
  <pre><code>exec("time",  $exec_results);
  </code></pre>
  
  <p>... the value of $exec_results is empty:</p>
  
  <pre><code>Array( )
  </code></pre>
  
  <p>I don't actually need to run date or time in my application but these are just examples of how the single line vs. multi-line output on the command line seems to change what gets back to PHP.</p>
  
  <p>The documents say:</p>
  
  <blockquote>
    <p>If the output argument is present, then the specified array will be filled with every line of output from the command.</p>
  </blockquote>
  
  <p>So why is the $exec_results array not being filled with all the lines seen when the time command is run in the command line?</p>
  
  <p>Notes - I have run the command line entries as the apache user to rule out privileges.</p>