Bugs item #1714451, was opened at 2007-05-07 13:13
Message generated for change (Comment added) made by collinwinter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1714451&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Windows
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: tzellman (tzellman)
Assigned to: Nobody/Anonymous (nobody)
Summary: subprocess.py problems errors when calling cmd.exe

Initial Comment:
An example:

>>> import subprocess
>>> proc = subprocess.Popen('"c:\Windows\system\ping.exe" "localhost"', 
>>> shell=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

'c:\Windows\system32\ping.exe" "localhost' is not recognized as an internal or 
external command, operable program or batch file.

This normally works from the cmd.exe prompt, so the command line is being 
passed incorrectly in the subprocess module.

My ACTUAL use case arises when I want to call the Microsoft compiler (CL.exe), 
and add include directories that have spaces in the name. For example:

"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\CL.exe" /TC /O2 /DNDEBUG /W3
/nologo /c /EHsc /errorReport:prompt /Idefault\ /I.. /I. /Idefault 
/I"C:\Program Files\GnuWin32" /DWIN32 ..\pcreposix.c /Fodefault\pcreposix.obj

The fix for this problem is to modify line 765 in subprocess.py, replacing it 
with:


args = comspec + " /s /c \"%s\"" % args.replace('""', '"')


The /s tells cmd.exe not to re-format the command line. We then encase the 
entire command line in double quotes. I also replace occurrences of "" with " 
in the arg string, in case the user already encased the command in double 
quotes.

With this fix, the commands execute correctly.

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

>Comment By: Collin Winter (collinwinter)
Date: 2007-06-05 14:36

Message:
Logged In: YES 
user_id=1344176
Originator: NO

tzellman, could you work up a real patch and a test case for this? Thanks.

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

Comment By: Gabriel Genellina (gagenellina)
Date: 2007-05-07 17:06

Message:
Logged In: YES 
user_id=479790
Originator: NO

Use a list of arguments instead, and please remember to use raw strings or
double backslashes:

proc = subprocess.Popen([r"c:\Windows\system\ping.exe","localhost"],
shell=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)


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

Comment By: tzellman (tzellman)
Date: 2007-05-07 13:20

Message:
Logged In: YES 
user_id=1090960
Originator: YES

This could likely be rejected.

I realize a solution to this w/o modifying the Python source is to encase
the expression yourself in double quotes. So, the example given would look
like:
>>> import subprocess
>>> proc = subprocess.Popen('""c:\Windows\system\ping.exe" "localhost""',
shell=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

And that will work.

Sorry for any confusion.


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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1714451&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to