title: Using diff in Linux using php's exec function
body: <p>I have to compare 2 xml files and generate a patch using php and Linux's diff command. Here's my code:</p>
  
  <pre><code>&lt;?php
  
  // script file location: /var/local/out/upload.php
  // ...
  
  // $templateName file location: /var/local/out/upload/example_word_template/word/document.xml
  // $filename file location: /var/local/out/upload/example_word/word/document.xml
  
  // $templateName value: upload/example_word_template/word/document.xml
  // $filename value: upload/example_word/word/document.xml
  
  $command = "diff /var/local/out/$templateName /var/local/out/$filename &gt; /var/local/out/patch.patch";
  exec($command);
  echo($command);
  
  ?&gt;
  </code></pre>
  
  <p>The browser outputs:</p>
  
  <p>diff /var/local/out/upload/example_word_template/word/document.xml /var/local/out/upload/example_word/word/document.xml > /var/local/out/patch.patch</p>
  
  <p>If I copy and paste the output and execute it directly in Linux, it runs just fine. But the script itself won't generate the patch file. What could be wrong?</p>