|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26657 exec() strange behaviour
Submitted: 2003-12-17 17:12 UTC Modified: 2003-12-22 13:22 UTC
From: dave at theholdens dot net Assigned:
Status: Closed Package: Program Execution
PHP Version: 4.3.4 OS: Win2K Server
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: dave at theholdens dot net
New email:
PHP Version: OS:


 [2003-12-17 17:12 UTC] dave at theholdens dot net
I have been trying to use exec() to run a legacy 16-bit DOS .EXE program to peform a complex calculatation that involves looking stuff up in dbase tables.  It refuses to work.  I have checked everything including permissions, paths, php.ini Safe Mode settings, etc.  All of the security is basically turned off.  The really curious behaviour is that my exec function call works fine for system commands like ipconfig and dir, but does not work for my DOS program, even when I move it into the windows\system32 directory beside all of the commands that DO work.  I have checked that the DOS program is sending back appropriate return codes.  The DOS program works fine when I type in the exact string being passed to the shell from the command line.

The same php code ran fine on a RedHat 8.x box, but broke when moved to Windows 2K3 server.

Reproduce code:
// this works fine
$output = exec("cmd /C ipconfig", $out_lines, $ret_code);
for($ctr=0; $ctr < count($out_lines); $ctr++)
  echo $out_lines[$ctr] . "<br>";

// this does not work (and IS copied to win\s32 dir and given ALL permissions for EVERYONE)
$output = exec("cmd /C c:\\windows\\system32\\grep -i \"safe\" c:\\windows\\php.ini", $out_lines, $ret_code);
for($ctr=0; $ctr < count($out_lines); $ctr++)
  echo $out_lines[$ctr] . "<br>";

Expected result:
The "works fine" code shows the ipconfig output stream exactly as expected and $ret_code contains 0.

Actual result:
The  "doesn't work" code shows nothing.  The $out_lines array is empty and $ret_code contains 1.  No errors appear in the log or the web page, even though error logging is turned on for both.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-18 03:28 UTC]
Please try using this CVS snapshot:
For Windows:

And are you aware that you're now calling com 2 times?
(exec() in PHP does 'cmd /c' itself)

 [2003-12-22 13:22 UTC] dave at theholdens dot net
Upgrading Apache to 2.0.48 fixed the problem.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 21:01:29 2024 UTC