Do not get the full answer from popen

Hi, I am starting a process called popen;

$handle = popen('python scriptos.py', "r"); while (!feof($handle)) { $data = fgets($handle); echo "> ".$data; } 

And I get only 3 rows from a process that returns 5 rows. I ran this exact command in CLi and I will get more response. It is as if he stops reading earlier (it may take time to complete and update the next 2 lines during operation, this is an indicator of progress).

Am I doing something wrong? Is proc_open more appropriate (I started to see if I can try this).

+4
source share
1 answer

The two missing lines are probably written to STDERR , and popen() returns a pointer to STDOUT.

You can get a pointer to STDERR with proc_open() or change the popen() to

 $handle = popen('python scriptos.py 2>&1', "r"); 

redirect STDERR to STDOUT, so they are included in your output.

+8
source

Source: https://habr.com/ru/post/1386561/


All Articles