Domanda

Hi I'm running a process with popen;-

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

And I'm only getting 3 lines from a process that returns 5 lines. I run this exact command in CLi and I will get more response. It's as if it stops reading early (it can take time to complete and updates the next 2 lines whilst working, it's a progress indicator).

Am I doing anything wrong? Is proc_open more suitable (i've started seeing if I can try that).

È stato utile?

Soluzione

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

You can either get a pointer for STDERR using proc_open(), or change the popen() line to

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

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top