php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #22662 shell_exec not working on windows XP
Submitted: 2003-03-12 11:33 UTC Modified: 2009-07-09 01:20 UTC
Votes:16
Avg. Score:4.6 ± 0.9
Reproduced:15 of 15 (100.0%)
Same Version:8 (53.3%)
Same OS:12 (80.0%)
From: pjaleysen at hotmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.3.2-RC OS: Windows XP
Private report: No CVE-ID: None
 [2003-03-12 11:33 UTC] pjaleysen at hotmail dot com
Hi,
shell_exec(),as well as exec(),system(), can only handle 'native' DOS applications like ping,copy,attrib etc.
either directly as a command, or though a *.bat file.

Executing other (DOS) applications like pkzip (for DOS) or (rar for dos) don't seem to work.
There is a thread of this issue at www.devshed.com (http://forums.devshed.com/t55038/s.html)

I am using:
-Windows XP
-Apache 1.3.27
-PHP4.3

All with the default configurations.

Kind regards
Patrick

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-12 11:45 UTC] andrew@php.net
How are you passing your params to shell_exec() ?

I know from personal experience, that shell_exec() requires me to load command.com to the interpreter, such as:

print shell_exec('cmd version');

This *should* print out your windows version...

~ Andrew Heebner
 [2003-03-12 11:47 UTC] andrew@php.net
Sorry, that should be shell_exec('cmd ver');

~ Andrew Heebner
 [2003-03-12 11:58 UTC] pjaleysen at hotmail dot com
like I said, the native  Windows commands work correctly. I tried putting cmd before a command, but invain.

This is a brief summary of the forum thread, found at http://forums.devshed.com/t55038/s.html):

//---------------------------------------------------
I am trying to use pkzip to compress documents.
I am running a windows PC, so I am trying to execute a DOS command.

I have so far:
<?php
$pkzip="C:/Progra~1/Apache~1/Apache/readwr~1/pkzip.exe";
$pkzipdirectory="C:/Progra~1/Apache~1/Apache/readwr~1/";
$command=$pkzip." ".$pkzipdirectory."myzip.zip"." ".$pkzipdirectory."mydoc.doc";


shell_exec($command);
?>
It doesnt work
//---------------------------------------------------------
shouldn't have to as long as cmd.exe is in your path.
can't believe its not really.

maybe try a little test like this and see what you get back,
then you'll know if its a path problem.....

<?php

$test = shell_exec("ping 192.168.0.1");
echo $test;

?>
//------------------------------------------------------
The ping works ok!
I can do the standard commands alright.
I tried:
1)using absolute directories (like above)
2) changing path=, to include the pkzip file (A dos version of pkzip)
3) changing to the 'long' directory notation (e.g progra~1 => program files)
//-------------------------------------------------
Executing commands in the shell from a PHP script only works 
when the program you are trying to execute resides in your 
system directory (windows 2000: c:\winnt\system32).
//-----------------------------------------
I might have a clue!?!?
e.g. I have a batchfile saying:

"echo this batchfile works"

running this with:
<?php
$test=shell_exec("run.bat ");
echo $test;
?>
echoos 'echo this batchfile works'

Shouldnt the 'echo' NOT be there in the echo $test? 
It's like it is just reading the line, instead of executing it.......
//------------------------
 [2003-03-12 17:01 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

4.2.3 is way too old.

 [2003-03-12 17:04 UTC] pjaleysen at hotmail dot com
I have the same problem with php4.3 (at home)
 [2003-03-12 17:05 UTC] sniper@php.net
Yes, but the snapshot is 4.3.2-dev so try it out.
We're about to release 4.3.2 soon.


 [2003-03-13 03:01 UTC] pjaleysen at hotmail dot com
HI, I tried it out with PHP Version 4.3.2-RC but the problem remains;
native MS-DOS commands work fine, other DOS-applications do not respond.

kind regards
Patrick
 [2003-03-13 06:25 UTC] hholzgra@php.net
%PATH% issue? (blind guess)
 [2003-03-13 06:33 UTC] pjaleysen at hotmail dot com
Nope, paths, all of that excluded.I tried to put some details below, comming from http://forums.devshed.com/t55038/s.html (which also deals with the various path issues. Many others also had a look at it).

At the very end of the forum there is an assumption that it is a WinXP problem, since win2000 works fine.
 [2003-03-15 03:42 UTC] pjaleysen at hotmail dot com
Executing Windows-based applications work alright, but not the ones running in DOS. e.g. I am using winzip now instead of pkzip.exe for dos. 

Because I have to use windows application, it will mke the php code less portable, since I have to use installed software
 [2003-06-03 17:52 UTC] spoon at nexdot dot net
This seems very close to what im experiencing.

I am using php 5.0.0-dev (updated about 2 weeks ago), but the problem has occured for me on 4.x.x versions. I use Windows XP Pro/Windows 2000 Server with my 5.0.0-dev. Apache 2 24

When i use ANY of the MANY methods for passing a system call

System
Shell_exec
Exec
``  (backtick)
Passthru

they all act the same (in this case, as a passthru), UNLESS with a native dos command (which i tried after reading this bug post).

The functions such as the 2 exec ones and the backticks should not output anything. I do this:

$string=exec/shell_exec/``;

when calling something such as ping/dir/echo, or any normal dos command, they work as expected... nothing is output to the browser (or above the php header have you) unless i do an

echo $string;

When i try to call a program such as gzip, $string has a length of 0 (or null) and the the output from the command appears in my browser (or above PHP headers if run from command line) without echo'ing. Other special parts of each system call functions also do not work, such as exec's array output, which is null unless a native dos command.
 [2004-04-28 20:00 UTC] clubland at gmx dot net
Hi all,

Platform:
IIS 6.0 / Windows 2003 Server

Problem:
shell_exec etc `s not working

Solution:
check rights on %SYS32%\cmd.exe

Chris
 [2004-08-03 05:57 UTC] wfrench at prevailnet dot net
I've had the same problem trying to use unzip.exe on XP with php 4.3.8.

Got some interesting results when I tried the dos batch file wrapper approach...

When I use the batch:
-----------------------------
@echo hello world
-----------------------------

it works like a champ.

but when I change the file thusly:
-----------------------------
unzip
@echo hello world
-----------------------------

if prints the following:
---------------------------------
c:\inetpub\wwwroot\svgwork>unzip hello world 
---------------------------------

Obviously it has prepended my command (unzip) with my web directory.  Not so obvious perhaps is what the '>' character is doing in there.
 [2009-07-09 01:17 UTC] bmcclory at gmail dot com
Can someone tell me why the following code will not work in Windows:

system("nmap $host");

Driving me nuts.  It works fine on apache servers and apparantly other IIS servers.  I don't know if i'm missing something in php.ini or what.  Other commands can be run from system(), just not nmap.
 [2009-07-09 01:20 UTC] pajoye@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 06:01:32 2024 UTC