php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60181 proc_open fails to read quoted whitespaced directories in Windows
Submitted: 2011-10-31 22:05 UTC Modified: 2021-08-16 12:25 UTC
Votes:17
Avg. Score:4.6 ± 0.8
Reproduced:11 of 13 (84.6%)
Same Version:4 (36.4%)
Same OS:8 (72.7%)
From: php at aldomx dot com Assigned: cmb (profile)
Status: Closed Package: Program Execution
PHP Version: 5.3.8 OS: Windows 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at aldomx dot com
New email:
PHP Version: OS:

 

 [2011-10-31 22:05 UTC] php at aldomx dot com
Description:
------------
Trying to execute via proc_open:

"C:/Program Files (x86)/Git/bin/git.exe" status --porcelain --untracked-files=all 
-- "D:/home/aldo/git/test whitespace"

is like not using them, since the result of STDERR is:

'C:/Program' is not recognized as an internal or external command,
operable program or batch file.

Test script:
---------------
<?php
$command = sprintf(
	'"%s" status --porcelain --untracked-files=all -- "%s"', // Git command
	'C:/Program Files (x86)/Git/bin/git.exe', // Git executable
	'D:/home/aldo/git/test with whitespace' // Directory
);
// $command = '"C:/Program Files (x86)/Git/bin/git.exe" status --porcelain --untracked-files=all -- "D:/home/aldo/git/test with whitespace"';

$proc = proc_open(
	$command,
	array (
		array ( "pipe", "r" ),
		array ( "pipe", "w" ),
		array ( "pipe", "w" )
	),
	$pipes
);

echo stream_get_contents( $pipes[2] );
// Outputs: 'C:/Program' is not recognized as an internal or external command,
// operable program or batch file.
?>

Expected result:
----------------
proc_open read the quotes correctly and manages to run git-status smoothly

Actual result:
--------------
'C:/Program' is not recognized as an internal or external command,
operable program or batch file.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-31 22:43 UTC] pajoye@php.net
Works just fine:

<?php
$descriptorspec = array(
   1 => array("pipe", "w"),
   2 => array("pipe", "w")
);

$cmd = '"c:\\test\\bin with space\\t.bat"';
$process = proc_open($cmd, $descriptorspec, $pipes);
echo stream_get_contents($pipes[1]);
echo stream_get_contents($pipes[2]);

$return_value = proc_close($process);
echo "command returned $return_value\n";

where t.bat contains only "dir" for testing
 [2011-10-31 22:51 UTC] php at aldomx dot com
Sorry, I forgot to specify "when you use 2 or more quoted arguments" (in my example git directory in program files and working directory)
 [2011-10-31 23:08 UTC] pajoye@php.net
Have you tries to use escape shell args?
 [2011-10-31 23:08 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-10-31 23:13 UTC] php at aldomx dot com
-Status: Feedback +Status: Open
 [2011-10-31 23:13 UTC] php at aldomx dot com
Yes, same result
 [2011-10-31 23:37 UTC] php at aldomx dot com
As additional information, using the same string with exec(), system() or passthru() works fine, proc_open() is the only one with this issue.
 [2011-11-01 00:11 UTC] pajoye@php.net
-Assigned To: +Assigned To: mattficken
 [2011-11-01 09:45 UTC] pajoye@php.net
Matt, please take a look to see what's going wrong here
 [2014-03-05 21:11 UTC] david at grudl dot com
Workaround: use array('bypass_shell' => TRUE) as last argument.
 [2014-05-24 17:15 UTC] martin at Liquidsculpture dot com
I tried the workaround of adding "array('bypass_shell' => TRUE)" as a parameter. While it eliminates the error message, the command still does not execute.

This still looks like a bug to me.
 [2014-05-24 17:20 UTC] martin at Liquidsculpture dot com
Sorry, I should add that I am using PHP 5.4.27 (cli) - still a problem.
 [2014-05-24 19:01 UTC] martin at Liquidsculpture dot com
I found the workaround that works: https://bugs.php.net/bug.php?id=49139 Put the entire command string in double quotes. I'm dropping this here to help the next person looking for the answer.
 [2017-10-24 06:43 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: mattficken +Assigned To:
 [2021-08-16 12:25 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-08-16 12:25 UTC] cmb@php.net
> Put the entire command string in double quotes.

Right.  This is now also documented in the PHP manual[1].  Also
note that as of PHP 7.4.0, you want to pass an array as $cmd.

[1] <https://www.php.net/proc_open>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC