[issue1524] os.system() fails for commands with multiple quoted file names
qiang [EMAIL PROTECTED] added the comment: in subprocess.py , change line 788: args = comspec + /c + args to: args = comspec + args it will be ok. -- nosy: +likes ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1524] os.system() fails for commands with multiple quoted file names
Sean Reifschneider [EMAIL PROTECTED] added the comment: I would agree with Georg that there isn't anything we can do about this. I had someone try from the Windows XP command shell and: dir /w reports that it can't run the combined command, where: dir /w works just fine. My conclusions are: This is a bug in the Windows shell (which os.system hands the command to). There is a work-around using call as pointed out by Jean-François The subprocess module is a better match for this, as you pass a tuple to make quoting unnecessary. According to the os module documentation, using subprocess is recommended in preference to using os.system(). -- nosy: +jafo priority: - normal resolution: - wont fix status: open - closed type: crash - behavior __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1524] os.system() fails for commands with multiple quoted file names
Jean-François Bastien added the comment: I confirm the problem. To resolve it try: os.system('call TheCommand MyOutput') -- nosy: +jfbastien __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1524] os.system() fails for commands with multiple quoted file names
Christian Heimes added the comment: Yes, it's necessary whenever the command part contains a space or other special characters. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1524] os.system() fails for commands with multiple quoted file names
Rafael Zanella added the comment: I don't have access to a Windows machine, but is it really necessary to quote the command part? I mean, on GNU/Linux if you pass a command wich has spaces , say e.g.: ls -lah, quoted it fails too, but if passed without quotes it runs just fine. -- nosy: +zanella __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1524] os.system() fails for commands with multiple quoted file names
New submission from Guy Mott: Given a call to os.system() with a command string like this: os.system('TheCommand MyOutput') # fails then the call fails with the following error message on the console: 'TheCommand MyOutput' is not recognized as an internal or external command, operable program or batch file. Note that both the executable file name and the redirected output file name are quoted. Apparently the command string is being parsed and the first quote is incorrectly being matched with the last quote. A more general statement of this bug might say that multiple quoted fields on a command line cause os.system() to fail. I have not done enough research to better characterize the problem. By contrast, if only one of the file names is quoted then the call to os.system() succeeds. E.g., these calls succeed: os.system('TheCommand MyOutput') # succeeds os.system('TheCommand MyOutput') # succeeds Of course this is a simplified example where it is not necessary to quote either file name. Real world examples include 2 file names with imbedded spaces. E.g.: os.system('The Command My Output') # fails 'The' is not recognized as an internal or external command, operable program or batch file. A further real-world example is a command line with full path specifications for both the executable file and the output file. Such path specifications may include imbedded spaces so both need to be quoted. However, quoting both causes os.system() to fail. E.g.: os.system(r'C:\New Folder\TheCommand C:\New Folder\MyOutput') # fails 'C:\New' is not recognized as an internal or external command, operable program or batch file. The above described scenario is the situation in the attached script that includes logic for finding an executable file that may not be found on the system path but is co-located with the Python script file. Thus the script and its companion file(s) may be moved from machine to machine and will work correctly even if not in a directory that is included on the system path. The script fails because the command line that it constructs, with executable and output file specifications quoted, fails in os.system(). Here is output from running the attached script: --- C:\New Folderbuggy.py strCmdLine=[ListMetadata 20071129Metadata.txt] 'ListMetadata 20071129Metadata.txt' is not recognized as an internal or external command, operable program or batch file. Could not find ListMetadata on path, looking in script directory strCmdLine=[C:\New Folder\ListMetadata 20071129Metadata.txt] 'C:\New' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File C:\New Folder\buggy.py, line 16, in module raise Exception(Could not locate command) Exception: Could not locate command --- Note that the command line that is constructed by the attached script runs just fine and produces the desired result if it is executed directly at a command line prompt. It is when executed via os.system() that the command line fails. Testing environment: OS = Windows XP Professional Python = 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] -- components: Extension Modules, Windows files: buggy.py messages: 57952 nosy: Quigon severity: major status: open title: os.system() fails for commands with multiple quoted file names type: crash versions: Python 2.5 Added file: http://bugs.python.org/file8828/buggy.py __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 __ #=== # This is example logic for Python code that depends upon an external executable # file. If the executable is found on the system path then no problem. # Otherwise, this script attempts to execute the executable in the same # directory where the script is located. # Unfortunately, this logic fails because os.system() fails when both the # executable and the output files are both quoted. Note that the command lines # that this code constructs work just fine at the command prompt. They fail in # os.system(). #=== import os.path import sys strCmdName = ListMetadata # name of our executable file strOutName = 20071129Metadata.txt # name of output file # Command line is constructed with both file names quoted for maximum generality. strCmdLine = '%s %s' % (strCmdName, strOutName) print strCmdLine=[%s] % strCmdLine nRtn = os.system(strCmdLine) # if os.system() fails (which it does) ... if (nRtn != 0): print 'Could not find %s on path, looking in script directory' % strCmdName # Create a new command line with a full executable file specification in our script directory.
[issue1524] os.system() fails for commands with multiple quoted file names
Christian Heimes added the comment: I don't think that we can do anything about your problem. The user of os.system() is responsible to do the quoting himself. os.system() is just a tiny wrapper around the low level C function. We don't plan to chance the fact that os.system() doesn't handling quoting. However the subprocess module is clever enough to do the quoting for you. -- nosy: +tiran __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1524] os.system() fails for commands with multiple quoted file names
Georg Brandl added the comment: Are you sure that the exact command line works in a Windows shell? Python does no processing on the string, it just hands it to the platform system() function, so if MS decided that to work different from a command prompt there's nothing we can do about. -- nosy: +georg.brandl __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1524] os.system() fails for commands with multiple quoted file names
Guy Mott added the comment: Are you sure that the exact command line works in a Windows shell? Yes, I tried running the exact same command line in a Windows shell and it worked fine. Note that the buggy.py script echoes the command line and then immediately calls os.system with it. E.g.: print strCmdLine=[%s] % strCmdLine nRtn = os.system(strCmdLine) I tried running the script in a shell window, watched it fail, then immediately cut and pasted the command line that had been echoed out by the script to the command line prompt in the same shell, ran it and it succeeded. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1524 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com