New submission from David Fraser <dav...@sjsoft.com>: (from http://stackoverflow.com/questions/1253122/why-does-subprocess-popen-with-shelltrue-work-differently-on-linux-vs-windows/1254322)
When using subprocess.Popen(args, shell=True) to run "gcc --version" (just as an example), on Windows we get this: >>> from subprocess import Popen >>> Popen(['gcc', '--version'], shell=True) gcc (GCC) 3.4.5 (mingw-vista special r3) ... So it's nicely printing out the version as I expect. But on Linux we get this: >>> from subprocess import Popen >>> Popen(['gcc', '--version'], shell=True) gcc: no input files Because gcc hasn't received the --version option. The docs don't specify exactly what should happen to the args under Windows, but it does say, on Unix, "If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional shell arguments." IMHO the Windows way is better, because it allows you to treat Popen(arglist) calls the same as Popen(arglist, shell=True) ones. The strange implementation is actually the UNIX one, which does the following (where each space separates a different argument): /bin/sh -c gcc --version It looks like the correct implementation (at least on Linux) would be: /bin/sh -c "gcc --version" gcc --version Since this would set the command string from the quoted parameters, and pass the other parameters successfully. >From the sh man page section for -c: Read commands from the command_string operand instead of from the standard input. Special parameter 0 will be set from the command_name operand and the positional parameters ($1, $2, etc.) set from the remaining argument operands. This patch seems to fairly simply do the trick, as well as testing it. ---------- components: Library (Lib) files: current-2.6.patch keywords: patch messages: 91492 nosy: davidfraser severity: normal status: open title: subprocess doesn't pass arguments correctly on Linux when shell=True type: behavior versions: Python 2.6 Added file: http://bugs.python.org/file14697/current-2.6.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6689> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com