|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21065 shell_exec seems not to work properly if result was false.
Submitted: 2002-12-17 06:41 UTC Modified: 2003-02-10 16:37 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: dj-bj at gmx dot net Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 4.2.3 OS: Windows 2000 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dj-bj at gmx dot net
New email:
PHP Version: OS:


 [2002-12-17 06:41 UTC] dj-bj at gmx dot net
Running PHP 4.2.3 on Windows 2000 Server shell_exec works fine and passes its output to the variable when the result of the executed command is true. 
However, if the command fails and the DOS-shell returns an error the result is no longer availiable in the variable but is passed directly to the page.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-19 19:15 UTC]
Please try using this CVS snapshot:
For Windows:

 [2002-12-20 02:50 UTC] dj-bj at gmx dot net
I installed this version using the old ini file - no errors execpt the one reported.
Still, the result of shell_exec is not passed to the variable but displayed on the page with added "

Content-type: text/html
X-Powered-By: PHP/4.4.0-dev

" after the error message.

In my script i control some nt services and therefor i tell shell_exec to execute net start / net stop. If a service has already been started and i attempt to start it again it returns the error "More help is available by typing NET HELPMSG 2182." like in DOS Shell on Windows but this error not passed to the variable.
 [2003-02-10 16:37 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

If you want to recieve the error messages append '2>&1' to the end of the command you are executing. This will work on any *nix based system as well as most recent Win32 server oses such as Windows NT and Windows 2000.
 [2003-02-11 01:41 UTC] dj-bj at gmx dot net
Thank you for the tip to add 2>&1 to the command. This prevents any crashed output from beeing sent to the page (take >nul for no output).
The documentation says:
shell_exec --  Execute command via shell and return complete output as string 
and not 
Execute command via shell and return complete output as string only if exectued command is true but crash when false..

However, thank you for your assistance.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Nov 24 09:01:23 2020 UTC