title: php exec bash scripts : No such file or directory
body: <p>I have a few bash and perl scripts which has been asked to be made executable through a web based interface. Nothing fancy, just for easy access.
  PHP seemed to be the quick and dirty solution for the purpose [through <code>exec()</code>]. So I turned off the safe mode in php.ini and tried</p>
  
  <pre><code>$output = array();
  exec('/var/www/vhosts/default/htdocs/scripts/RUN.sh',$OUTPUT);
  print_r($output);
  var_dump($output);
  </code></pre>
  
  <p>Now whatever files are accessed in the RUN.sh script (accessed though a relative path) are not found. Is there any way of getting this to work without giving complete path to every single redirect (or any file for that matter) that is being accessed in the scripts?</p>
  
  <hr>
  
  <p>After applying the accepted solution:</p>
  
  <p>Say one line form the script:</p>
  
  <pre><code>time python idsplitter.py OUTPUT/TMP/tokens OUTPUT/token_splits
  echo "done"
  </code></pre>
  
  <p>While the <code>time</code>-s output gets pushed to error_log file, "done" is never passed to the $OUTPUT array. The returned value in the third argument to exec(), when printed on page gives <code>0</code>.</p>
  
  <hr>
  
  <p>Update:
  <code>time</code> command puts it out to stderr so if do `</p>
  
  <pre><code>t=`time some_command 2&gt;&amp;1`
  </code></pre>
  
  <p>then also nothing gets stored in t. So that makes sense. Thanks for the help everyone ...</p>