title: Running at from PHP gives no output
body: <p>I've been wrestling with <code>exec()</code>, trying to capture the output from it when I add a task using the <code>at</code> Unix system command. My problem is that it is giving no output when run from my script, however running it from the terminal <em>and</em> PHP in interactive mode prints out a couple of lines.</p>
  
  <p>The command I want to execute is this:</p>
  
  <pre><code>echo exec("echo 'php -f /path/to/file.php foo=1' | at now + 1 minutes", $result);
  </code></pre>
  
  <p><code>var_dump()</code> gives <code>string(0) ""</code>, and <code>print_r()</code> spits out <code>Array ()</code>. I've tried using <code>shell_exec()</code>, which outputs <code>NULL</code>, however the following outputs <code>hi</code> when run in a web page context:</p>
  
  <pre><code>echo exec("echo 'hi'");
  </code></pre>
  
  <p>This also outputs stuff:</p>
  
  <pre><code>echo exec("atq");
  </code></pre>
  
  <p>However, as soon as I use <code>at</code>, nothing is output. How can I get the output of:</p>
  
  <pre><code>exec("echo 'php -f /path/to/file.php foo=1' | at now + 1 minutes", $result);
  </code></pre>
  
  <p>Because at present it outputs nothing when run as "normal" by PHP through Apache, however running the command in the terminal as well as in PHP's interactive console gives me the expected result of something like:</p>
  
  <pre><code>php &gt; echo exec("echo 'php -f /path/to/file.php foo=1' | at now + 1 minutes", $result);
  warning: commands will be executed using /bin/sh
  job 1219 at Sun Jun 10 12:43:00 2012
  </code></pre>
  
  <p><code>safe_mode</code> is off, and I cannot work out why I don't get any output from <code>at</code> with a piped-in echo statement, when executing <code>atq</code> or any other commend with <code>exec()</code> gives me output. I've searched and read <a href="https://stackoverflow.com/questions/2414647/calling-php-from-php-through-exec-gives-no-result">this question</a>, all to no avail. </p>
  
  <p>How can I get <code>exec()</code> to return the output from <code>at</code> to either a string, or an array if using a second argument with <code>exec()</code>?</p>