#48729 [Com]: proc_open doesn't read from stdin
| From: | kripper3 at hotmail dot com | Date: | Tue, 07 Jul 2009 16:48:35 +0000 |
| Subject: | #48729 [Com]: proc_open doesn't read from stdin | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-139415@lists.php.net to get a copy of this message | ||
ID: 48729
Comment by: kripper3 at hotmail dot com
Reported By: kripper at imatronix dot cl
Status: Feedback
Bug Type: Streams related
Operating System: Windows XP SP3
PHP Version: 5.2.10
Assigned To: pajoye
New Comment:
It works on 5.3 (CVS), only with php.exe.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2009-07-03 16:22:21] pajoye@php.net
Please try using CLI, not cgi.
------------------------------------------------------------------------
[2009-07-03 16:19:46] kripper3 at hotmail dot com
Tested on PHP 5.3 (5.3.1-dev) (CVS), released 2009-Jul-03 17:00:00.
proc_open() is still not able to read from stdin on windows, when
running PHP from a DOS shell.
------------------------------------------------------------------------
[2009-06-30 07:52:33] pajoye@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2009-06-30 05:16:57] kripper3 at hotmail dot com
HINT for reproducing:
1) Download plink.exe
(http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe) to C:\ for
testing a command which expects stdin.
2) Copy this script to C:\test.php
---
<?
$espec_descriptor = array(
0 => fopen('php://stdin', 'r'),
1 => fopen('php://stdout', 'w'),
2 => array("file", "C:\\error-output.txt", "a")
);
$cmd = "C:\\plink.exe root@hostifex.com";
$process = proc_open($cmd, $espec_descriptor, $pipes);
if (is_resource($process)) {
echo "The command was supposed to prompt the password (it works on
5.1.2)\n";
proc_close($process);
} else {
echo "Trivial Error. Please check your setup for reproducing the
problem.\n";
}
?>
---
3) Execute in DOS Shell:
C:\PHP\php-cgi.exe C:\test.php
4) A prompt reading from stdin is expected (but fails con 5.2.x).
It works with: http://museum.php.net/php5/php-5.1.2-Win32.zip
5) Check the C:\error-output.txt if you get other results.
6) (Cleaning) Delete C:\Test.php and C:\error-output.txt.
Thanks.
------------------------------------------------------------------------
[2009-06-30 03:35:07] kripper at imatronix dot cl
Description:
------------
proc_open() doesn't read from stdin, when running PHP from console.
Reproduce code works on PHP 5.1.2.
popen works, but seems not to be suited for running interactive shell
commands from PHP.
Console scripts trying to run interactive commands will fail.
Reproduce code:
---------------
$espec_descriptor = array(
0 => fopen('php://stdin', 'r'),
1 => fopen('php://stdout', 'w'),
2 => array("file", "C:\\error-output.txt", "a")
);
$cmd = "<any command reading from stdin, for example: plink.exe>";
$process = proc_open($cmd, $espec_descriptor, $pipes);
if (is_resource($process)) {
set_time_limit(0);
return proc_close($process);
} else {
return -1;
}
Expected result:
----------------
proc_open() should run the command and allow it to read from stdin.
Actual result:
--------------
Commands fail to read from stdin and close inmediatly.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48729&edit=1