#25727 [Opn->Fbk]: popen returns wrong exitcode

From: Date: Fri, 03 Oct 2003 23:17:17 +0000
Subject: #25727 [Opn->Fbk]: popen returns wrong exitcode
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-48531@lists.php.net to get a copy of this message
 ID:               25727
 Updated by:       sniper@php.net
 Reported By:      eru@php.net
-Status:           Open
+Status:           Feedback
 Bug Type:         Filesystem function related
 Operating System: i386 Linux
 PHP Version:      4CVS-2003-10-03 (stable)
 New Comment:

Exactly what linux version is this with?
What glibc? Gcc? etc..



Previous Comments:
------------------------------------------------------------------------

[2003-10-03 11:10:08] eru@php.net

No change, I still get the Actual result (with fgets).

------------------------------------------------------------------------

[2003-10-02 19:31:25] iliaa@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

I too (like sniper) get the correct output int(0)

------------------------------------------------------------------------

[2003-10-02 10:45:08] sniper@php.net

For me the output is (when replaced fread with fgets) this:

FOO
int(0)



------------------------------------------------------------------------

[2003-10-02 09:00:17] wez@php.net

If you pclose before all the data has been read, you might
cause the child process to terminate abnormally, and this
might explain the exit code.

In addition, fread() will only read a "packet" from a pipe,
so you might not be getting all the data before you pclose
it.

*that's* what fread/fgets() has got to do with it;
in future, please don't question my suggestions and just
provide the requested feedback.



------------------------------------------------------------------------

[2003-10-02 08:00:43] eru@php.net

Description:
------------
Apparently this has something to do with the environment-variables in
the shell, popen uses to execute the command. If I replace "echo FOO"
with "export" I get the whole line of variables and then it fails,
whereas the successful execution only has one, BASH=/bin/sh. I use php
-n so no php.ini is used.

Reproduce code:
---------------
<?php
$pp = popen("echo FOO", "r");
echo fread($pp, 4096);
var_dump(pclose($pp));
?>


Expected result:
----------------
FOO
int(0)


Actual result:
--------------
FOO
int(-1)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25727&edit=1


Thread (15 messages)

« previous php.bugs (#48531) next »