I'd say it's quite a simple question but I'm stuck with it:
I need to communicate with external program (specifically, Exim) run with some debug options. As I run it from linux shell, it goes like this: run exim -bh 11.22.33.44
, then read its output (both STDOUT and STDERR), the type in some line from SMTP dialog, then read Exim output again, type another SMTP line and so on. And it's nicely works while I'm on bash shell, but as I run it from PHP script it stuck in STDIN read loop.
I use proc-open
:
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", 'w'),
2 => array("pipe", 'w')
);
$process=proc_open('/usr/sbin/exim -bh 11.22.33.44', $descriptorspec, $pipes, NULL, NULL);
if (is_resource($process)) {
stream_set_blocking($pipes[1], 1);
stream_set_blocking($pipes[2], 1);
while(!feof($pipes[2])) {
$txt2 = fgets($pipes[2]);
}
while(!feof($pipes[1])) {
$txt2 = fgets($pipes[1]);
}
fwrite($pipes[0], 'HELO testhost');
...
}
Looks simple, but as it goes to the end of first STDERR, it stuck.
Tried both blocking and unblocking mode, tried to swap reading from STDERR and STDIN - no luck so far.
Please point me the right way to do that!