Bugs item #1710802, was opened at 2007-05-01 22:46 Message generated for change (Comment added) made by astrand You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1710802&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: Python Library Group: None >Status: Closed >Resolution: Wont Fix Priority: 5 Private: No Submitted By: Patrick Mézard (pmezard) Assigned to: Peter Åstrand (astrand) Summary: subprocess must escape redirection characters under win32 Initial Comment: Hello, For some reason, subprocess.Popen arguments are not processed correctly when one of them contains a redirection character ("<>&|") when calling a batch file. Unittest and patch are attached below. Here are the steps to reproduce it: callee.py """ import sys print sys.argv """ callee.bat """ python callee.py %* """ caller.py """ import subprocess args = [ 'a<b', 'a>b', 'a|b', 'a&b', ] for arg in args: subprocess.check_call(['callee.bat', arg]) """ Then: """ >python caller.py The system cannot find the file specified. Traceback (most recent call last): File "caller.py", line 22, in <module> subprocess.check_call(['callee.bat', arg]) File "C:\Python251\lib\subprocess.py", line 461, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['callee.bat', 'a<b']' returned non-zero exit status 1 """ With: """ Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> """ ---------------------------------------------------------------------- >Comment By: Peter Åstrand (astrand) Date: 2007-05-04 23:13 Message: Logged In: YES user_id=344921 Originator: NO I'm testing with a simpler pair of files: callee.bat: echo arg1 %1 echo arg2 %2 echo arg3 %3 caller.py: import subprocess subprocess.call(['callee.bat', 'a<b']) This fails. What happens is that CreateProcess is called with: lpApplicationName=None lpCommandLine="callee.bat a<b" As far as I know, this is correct: I can't find anything in the documentation of CreateProcess that indicates that "<" is a magical meta character in this context. I find it very surprising that CreateProcess behaves like this. After some further investigations, I've found out that it's the fact that we are calling a batch file that's the problem. CreateProcess does not fail on a command line such as "view.exe a<b". Indeed, the documentation as well as a community comment on http://msdn2.microsoft.com/en-us/library/ms682425.aspx indicates that batch files are handled in a special (broken?) way. I'm reluctant to accept the attached patch. It might for this particular situation, but as far as I can tell, we are following the documented API. You should be able to work around this problem by quoting in your application. ---------------------------------------------------------------------- Comment By: Neal Norwitz (nnorwitz) Date: 2007-05-02 08:38 Message: Logged In: YES user_id=33168 Originator: NO Peter, can you take a look at this? ---------------------------------------------------------------------- Comment By: Patrick Mézard (pmezard) Date: 2007-05-01 22:47 Message: Logged In: YES user_id=1660346 Originator: YES File Added: fix_subp ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1710802&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com