title: php is failing to call shell script (js -> php -> sh)
body: <p>I want to execute a shell script from webpage. So I started with a simple arithmatic sum program. Webpage has two fields and a submit button. If user clicks submit button, javascipt validates and then calls php file through <code>ajax</code>. Php file extracts the arguments and call <code>sum.sh</code> with those arguments.<br>
  But i'm unable to do it. Here is my code.</p>
  
  <p><strong>design3.html</strong>:</p>
  
  <pre><code> &lt;body&gt;
   &lt;form action='' method='post'&gt;
          &lt;center&gt;
             arg1: &lt;input type='text' name='t1' id="arg1"/&gt; &lt;br&gt;&lt;br&gt;
             arg2: &lt;input type='text' name='t2' id="arg2"/&gt; &lt;br&gt;&lt;br&gt;
             &lt;input type='submit' name='use_button' value='Sum' onclick="addContent()"/&gt;
          &lt;/center&gt;
      &lt;/form&gt;
  
   &lt;script type="text/javascript"&gt;
      function addContent(){
          var a = document.getElementById('arg1').value;
          var b = document.getElementById('arg2').value;
  
          if(a == "" || b == "") {
              alert("Please fill all fields");
              return;
          }
  
          var request = $.ajax({
                     url: "add.php",
                     type: "POST",
                     dataType: "html",
                     data: {functionname: 'add', arguments:[a, b]}
           });
  
           request.done(function(msg) {
                     alert(msg);
            });
  
            request.fail(function(jqXHR, textStatus) {
                     alert( "Request failed: " + textStatus );
            });
  
      }
  
  &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>add.php</strong>:</p>
  
  <pre><code>&lt;?php
  if (is_ajax()) {
      if( isset($_POST['functionname']) ) {
          switch($_POST['functionname']) {
              case 'add':
                  $var1 = $_POST['arguments'][0];
                  $var2 = $_POST['arguments'][1];
                  $cmd = 'sh ./sum.sh'.' '.$var1.' '.$var2;
                  $output = shell_exec($cmd);
                  echo $output;
                  break;
           }
       }
  }
  
  function is_ajax() {
      return isset($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
  }
  ?&gt;
  </code></pre>
  
  <p><strong>sum.sh</strong>:</p>
  
  <pre><code>#!/bin/bash
  var1=$1
  var2=$2
  echo `expr $var1 + $var2`
  </code></pre>
  
  <p>I'm new to this JS and PHP. But tried hard to do this. If I'm testing seperately it's working. When I write html and php in same file without JS then my script is working. If I'm not calling <code>sum.sh</code> script file in php, it is working. Coming to total integration it is failing. I'm getting this error from browser alert <code>Request failed: error</code>.</p>