title: can not get output when use php proc_open execute command?
body: <p>I write a php function to exec shell script,but I can not get output if the command execute correctly,the function and shell script as follow:</p>
  
  <h2>PHP function:</h2>
  
  <pre><code>function execWithTimeout($cmd, $timeout=5) {
      //initiate retrun value
      $output = '';
      $res='';
      $cause='';
  
      $descriptorspec = array(
      0 =&gt; array("pipe", "r"),
      1 =&gt; array("pipe", "w"),
      2 =&gt; array("pipe", "w"));
      $pipes = array();
  
      $timeout += time();
      $process = proc_open($cmd, $descriptorspec, $pipes);
      if (is_resource($process)) {
          //loop check
          do {
              $timeleft = $timeout - time();
              $read = array($pipes[1]);
              stream_select($read, $write = NULL, $exeptions = NULL, $timeleft, NULL);
              if (!empty($read)) {
                  $output .= fread($pipes[1], 8192);
              }
          } while (!feof($pipes[1]) &amp;&amp; $timeleft &gt; 0);
  
          if ($timeleft &lt;= 0) {
              proc_terminate($process);
              $res=false;
              $cause='timeout';
          } else {
              $res=true;
          }
          fclose($pipes[0]);
          fclose($pipes[1]);
          fclose($pipes[2]);
          proc_close($process);
      }else{
          $res=false;
          $cause='execute command failed';
      }
      $retVal=array('result'=&gt;$res,'output'=&gt;$output,'cause'=&gt;$cause);
      return $retVal;
  }
  </code></pre>
  
  <h2>this command is as follow:</h2>
  
  <pre><code> $cmd='ssh root@192.168.1.100'.'"disk_sd=\`fdisk -l|grep \'Disk /dev/sd\'|awk \'{print \$2}\'|sed -n \'s/\/dev\///p\'|sed -n \'s/://p\'\`;
           disk_hd=\`fdisk -l|grep \'Disk /dev/hd\'|awk \'{print \$2}\'|sed -n \'s/\/dev\///p\'|sed -n \'s/://p\'\`;
           disk_cciss=\`fdisk -l|grep \'Disk \/dev\/cciss\'|awk \'{print \$2}\'|sed -n \'s/\/dev\///p\'|sed -n \'s/://p\'\`;
           disk_xvda=\`fdisk -l|grep \'Disk \/dev\/xvda\'|awk \'{print \$2}\'|sed -n \'s/\/dev\///p\'|sed -n \'s/://p\'\`;
           disks=\$disk_sd\" \"\$disk_hd\" \"\$disk_cciss\" \"\$disk_xvda;
           diskTotal=0;
           diskFree=0;
           diskUsed=0;         
           for d in \$disks;           
           do
             diskTotal=\`fdisk -l|grep \'Disk /dev/\'\$d\':\'|awk \'{print \$5}\'\`;
             for s in \`df -l|grep \$d|awk \'{print \$4*1024}\'\`;
                do 
                diskFree=\`echo \$diskFree \$s|awk \'{print \$1+\$2}\'\`;
             done;              
             for s in \`df -l|grep \$d|awk \'{print \$3*1024}\'\`;
                do 
                diskUsed=\`echo \$diskUsed \$s|awk \'{print \$1+\$2}\'\`;
             done;         
           done;
           diskUsage=\`echo \$diskUsed \$diskTotal|awk -F\' \' \'{print \$1/\$2*100}\'\`;         
           memTotal=\`free |awk \'/Mem:/{print \$2}\'\`;
           memUsed=\`free |awk \'/Mem:/{print \$3}\'\`;
           memFree=\`free |awk \'/Mem:/{print \$4}\'\`;
           memUsage=\`free |awk \'/Mem:/{print \$3/\$2*100}\'\`;
           cpuUsage=\`top -b -n 1|awk /^Cpu/\'{print 100-\$5}\'|cut -f1 -d %\`;
           out=\'{\';
           out=\$out\'\"diskTotal\":\'\$diskTotal;
           out=\$out\',\"diskUsed\":\'\$diskUsed;
           out=\$out\',\"diskFree\":\'\$diskFree;
           out=\$out\',\"diskUsage\":\'\$diskUsage;
           out=\$out\',\"memTotal\":\'\$memTotal;
           out=\$out\',\"memUsed\":\'\$memUsed;
           out=\$out\',\"memFree\":\'\$memFree;
           out=\$out\',\"memUsage\":\'\$memUsage;
           out=\$out\',\"cpuUsage\":\'\$cpuUsage;
           out=\$out\'}\';
           echo \$out;"';
  </code></pre>