PHP exec command is not returning full data from Python script
<p>I am connecting to a server through PHP SSH and then using exec to run a python program on that server. </p>

<p>If I connect to that server through putty and execute the same command through command line, I get result like:</p>

<blockquote>
  <p>Evaluating....</p>
  
  <p>Connecting....</p>
  
  <p>Retrieving data....</p>
  
  <p>1) Statement 1</p>
  
  <p>2) Statement 2</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>N) Statement N</p>
</blockquote>

<p>Python program is written by somebody else...</p>

<p>When I connect through SSH php, I can execute <code>$ssh-&gt;exec("ls")</code> and get the full results as proper as on server command line. But when I try <code>$ssh-&gt;exec("python myscript.py -s statement 0 0 0");</code> I couldn't  get the full results but I get a random line as an ouput.</p>

<p>In general, if somebody had experienced the same issue and solved, please let me know.</p>

<p>Thanks</p>

<p>Perhaps it's caused by buffering of the output. Try adding the <code>-u</code> option to your Python command - this forces stdout, stdin and stderr to be unbuffered.</p>

php python ssh centos exec