ID:               25361
 Updated by:       [EMAIL PROTECTED]
 Reported By:      sam at freepeers dot com
 Status:           Feedback
 Bug Type:         Program Execution
 Operating System: Windows 2000
 PHP Version:      4.3.2
 New Comment:

It may be that the /S is not required.

http://pastie.caboo.se/84306


Previous Comments:
------------------------------------------------------------------------

[2007-08-02 09:28:08] [EMAIL PROTECTED]

And thanks to Ashar Lohmar <[EMAIL PROTECTED]>, as he put me onto
this fix. He had a similar issue with wscript.

------------------------------------------------------------------------

[2007-08-02 09:22:46] [EMAIL PROTECTED]

For Windows NT+ (i.e. not win98-), this SEEMS to work.

cmd /s /c ""your long command" "another file""

Compare this against ...

cmd /c "your long command" "another file"

which doesn't work.

The /S option basically treats the rest of the string in quotes as a
command line.

This is slightly different behaviour.


%COMPSPEC% /S /C ""C:\Program Files\Internet Explorer\IEXPLORE.EXE"
"http://www.php.net"";


This is a patch to proc_open.c which I think should deal with the
issue. It may need to be optimized.

Index: proc_open.c
===================================================================
RCS file: /repository/php-src/ext/standard/proc_open.c,v
retrieving revision 1.57
diff -u -r1.57 proc_open.c
--- proc_open.c 28 May 2007 23:00:25 -0000      1.57
+++ proc_open.c 2 Aug 2007 09:21:02 -0000
@@ -740,7 +740,12 @@
        if (bypass_shell) {
                newprocok = CreateProcess(NULL, command, &security, &security, 
TRUE,
NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd, &si, &pi);
        } else {
-               spprintf(&command_with_cmd, 0, "%s /c %s", GetVersion() < 
0x80000000
? COMSPEC_NT : COMSPEC_9X, command);
+               if (GetVersion() < 0x80000000) {
+                       /* Wrap command in quotes and use the /s parameter to 
pass quotes
to the command line. */
+                       spprintf(&command_with_cmd, 0, "%s /s /c \"%s\"", 
COMSPEC_NT,
command);
+               } else {
+                       spprintf(&command_with_cmd, 0, "%s /c %s", COMSPEC_9X, 
command);
+               }
 
                newprocok = CreateProcess(NULL, command_with_cmd, &security,
&security, TRUE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd,
&si, &pi);
 
http://pastie.caboo.se/84303

------------------------------------------------------------------------

[2003-09-02 18:08:10] [EMAIL PROTECTED]

PHP uses "cmd.exe /c" for executing programs under windows.
You can try your examples on command line:

cmd.exe /c "your long command" "another file"

And you'll see it does not work. This is not PHP problem but yet
another windows problem. 

You must always use the '8.3' format of the paths/filenames.



------------------------------------------------------------------------

[2003-09-02 11:07:00] sam at freepeers dot com

Description:
------------
Running PHP on Windows 2000 with IIS 5.

Basic program executation does not work in certain cases. 

This is ok:

$output = `C:\executable.exe C:\\file1.txt`;

Now, lets suppose that both the filename and the executable names
contain spaces, and therefore each are to be enclosed in quotes.  Then
it fails:

This is not ok:

$output = `"C:\executable.exe" "C:\\file1.txt"`;

This is ok again:

$output = `C:\executable.exe "C:\\file1.txt"`;

This is also ok:

$output = `"C:\executable.exe" C:\\file1.txt`;

So, the problem arises when BOTH the command and the file are enclosed
in quotes.  In some cases you do need to enclose both the command and
the file in quotes. You will not be able to.

This affects all forms of command execution (exec, system,
backticks...)
  

Reproduce code:
---------------
1.  Create file called "Test.txt" and put it into C: drive.    Put some
random text in it.

2.  Try this code:

<?php

$output = "";
$output = `more C:\\Test.txt`;
echo "Test.txt contains $output.  This works<br><br>";

$output = "";
$output = `"more" C:\\Test.txt`;
echo "Test.txt contains $output.  This works<br><br>";

$output = "";
$output = `more "C:\\Test.txt"`;
echo "Test.txt contains $output.  This works<br><br>";

$output = "";
$output = `"more" "C:\\Test.txt"`;
echo "Test.txt contains $output.  This does not works<br><br>";

?>

Expected result:
----------------
Test.txt contains Contents of file. . This works

Test.txt contains Contents of file. . This works

Test.txt contains Contents of file. . This works

Test.txt contains Contents of file. . This does not works

Actual result:
--------------
Test.txt contains Contents of file. . This works

Test.txt contains Contents of file. . This works

Test.txt contains Contents of file. . This works

Test.txt contains . This does not works


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25361&edit=1

Reply via email to