php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35961 executing programs with spaces in program name and parameters fails.
Submitted: 2006-01-10 12:58 UTC Modified: 2008-07-15 10:11 UTC
From: rquadling at gmail dot com Assigned: scottmac (profile)
Status: Closed Package: CGI/CLI related
PHP Version: 5.1.1 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2006-01-10 12:58 UTC] rquadling at gmail dot com
Description:
------------
Within windows CMD32, the following works (obviously you will need to have a Windows system with Internet Explorer installed).

"C:\Program Files\Internet Explorer\IEXPLORE.EXE"

Will load Internet Explorer.

In PHP run from the CLI ...

<?php
$sOutput = shell_exec('"C:\Program Files\Internet Explorer\IEXPLORE.EXE"');
?>

Will load Internet Explorer and wait until it is closed.

If you want to pass the program a parameter then you would wrap the parameter with double quotes.

e.g.

From the command line ...

"C:\Program Files\Internet Explorer\IEXPLORE.EXE" "http://www.google.com"

Will load Internet Explorer and place you at Google.

If you try the same sort of thing in PHP ...

<?php
$sOutput = shell_exec('"C:\Program Files\Internet Explorer\IEXPLORE.EXE" "http://www.google.com"');
?>

You get an error of ...

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



Reproduce code:
---------------
<?php
$sOutput = shell_exec('"C:\Program Files\Internet Explorer\IEXPLORE.EXE" "http://www.google.com"');
?>

Expected result:
----------------
Internet Explorer loads with the Google page being displayed.

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-10 13:49 UTC] tony2001@php.net
Not PHP problem.
See bug #25361.
 [2006-01-10 14:00 UTC] rquadling at gmail dot com
Well, doesn't that just suck!
 [2008-05-30 10:14 UTC] rquadling@php.net
[11:11]	<Pierre>	RichardQ, assign these bugs to me and I will dispatch them if necessary
 [2008-06-06 09:35 UTC] rquadling@php.net
This was fixed.

HEAD : http://cvs.php.net/viewvc.cgi/TSRM/tsrm_win32.c?r1=1.34&r2=1.35
5.2x : http://cvs.php.net/viewvc.cgi/TSRM/tsrm_win32.c?r1=1.27.2.1.2.8&r2=1.27.2.1.2.9
5.3x : http://cvs.php.net/viewvc.cgi/TSRM/tsrm_win32.c?r1=1.27.2.1.2.7.2.1&r2=1.27.2.1.2.7.2.2

Can the 5.2x commit be reversed?

This caused a minor issue with phd for 5.2. Whilst it is easily fixed it is a BC mid version (5.2.6 vs 5.2.7-dev).

Having it at 5.3+ allows the BC to be documented as part of the changes to 5.3.

Thank you.

Richard Quadling.
 [2008-07-13 18:44 UTC] pajoye@php.net
Scott, please confirm it has been reverted in 5.2 :)
 [2008-07-15 10:11 UTC] pajoye@php.net
for the record here, it was reverted from 5.2
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Aug 04 05:01:24 2021 UTC