|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48729 proc_open doesn't read from stdin
Submitted: 2009-06-30 03:35 UTC Modified: 2009-07-07 16:57 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kripper at imatronix dot cl Assigned: pajoye (profile)
Status: Not a bug Package: Streams related
PHP Version: 5.2.10 OS: Windows XP SP3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: kripper at imatronix dot cl
New email:
PHP Version: OS:


 [2009-06-30 03:35 UTC] kripper at imatronix dot cl
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)) {
		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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-30 05:16 UTC] kripper3 at hotmail dot com
HINT for reproducing:

1) Download 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";

$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";
} 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:

5) Check the C:\error-output.txt if you get other results.

6) (Cleaning) Delete C:\Test.php and C:\error-output.txt.

 [2009-06-30 07:52 UTC]
Please try using this CVS snapshot:
For Windows:

 [2009-07-03 16:19 UTC] 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-07-03 16:22 UTC]
Please try using CLI, not cgi.
 [2009-07-07 16:48 UTC] kripper3 at hotmail dot com
It works on 5.3 (CVS), only with php.exe.
 [2009-07-07 16:57 UTC]
there is no such thing as stdin in other SAPI. It is implemented (fixed) only in CLI.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 11:01:35 2024 UTC