classification
Title: subprocess.list2cmdline doesn't do pipe symbols
Type: behavior Stage:
Components: Windows Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: chops@demiurgestudios.com, exarkun, gregory.p.smith, piotr.dobrogost
Priority: normal Keywords: easy

Created on 2007-10-18 17:40 by chops@demiurgestudios.com, last changed 2013-08-04 12:15 by piotr.dobrogost. This issue is now closed.

Messages (9)
msg56534 - (view) Author: Andrew Moise (chops@demiurgestudios.com) Date: 2007-10-18 17:40
I expected subprocess.list2cmdline() to convert my list of arguments
into a command line which results in behavior equivalent to the Unix
exec() functions -- that is, that I can safely pass arbitrary characters
to it and it'll make it such that those characters are escaped.  It
looks to me, though, like it doesn't handle the pipe symbol, so that if
I call list2cmdline(['echo', 'foo|bar']), I get the command line 'echo
foo|bar' instead of 'echo "foo|bar"' as I would expect.

If this is actually a result of my misunderstanding (or if it's fixed in
a more recent version), please accept my apologies.
msg60242 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2008-01-19 22:49
fixed in trunk r60115 (2.6).
msg108134 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2010-06-18 20:04
I reverted r60115 from trunk (2.7) in r82075 and from py3k in r82076.
msg108188 - (view) Author: Andrew Moise (chops@demiurgestudios.com) Date: 2010-06-19 17:47
Why is this bug invalid?
msg108189 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2010-06-19 17:51
See the commit message for r82075 and the discussion on issue8972 and issue7839.
msg108191 - (view) Author: Andrew Moise (chops@demiurgestudios.com) Date: 2010-06-19 18:08
Hm, I'm not sure I understand.  After r82075, will list2cmdline(['echo', 'foo|bar']) return 'echo foo|bar', or will it return 'echo "foo|bar"'?
msg108194 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2010-06-19 18:16
It will return the former.

To clarify, it's true that there appears to be a problem with Popen(['echo', 'foo|bar'], shell=True).  That is being tracked in issue7839.

What's invalid is the report that list2cmdline() should be quoting strings with | in them.  list2cmdline() is documented as being an implementation of the quoting convention implemented by the MS C runtime.  That quoting convention does not require | to be quoted.

It's cmd.exe which requires | to be quoted (if it is to be part of an argument value, rather than to indicate a command pipeline of some sort).  cmd.exe quoting rules need to be addressed separately from the MS C quoting rules used even if cmd.exe isn't involved.
msg108201 - (view) Author: Andrew Moise (chops@demiurgestudios.com) Date: 2010-06-19 18:36
Okay, makes sense.  It sure would be nice on Windows to have an equivalent of list2cmdline() that works for the shell.  I actually don't have immediate access to the code anymore, but I remember having to fool around with list2cmdline in the first place because it was difficult to do what I wanted without passing things through the shell (maybe I was spawning a process on Windows and capturing input/output/stderr; I don't remember in detail).

Maybe the solution is to make what I was trying to do easier without fooling with the shell instead of playing the fool's game of trying to improve the ability to deal with the shell so we can pass things through it unnecessarily.

Anyway, thanks.
msg194357 - (view) Author: Piotr Dobrogost (piotr.dobrogost) Date: 2013-08-04 12:15
>Maybe the solution is to make what I was trying to do easier without
>fooling with the shell instead of playing the fool's game of trying to
>improve the ability to deal with the shell so we can pass things
>through it unnecessarily.

You are too harsh for yourself :) We should be able to make use of shell easily the same way it's possible in other languages like Perl or Ruby.

>It sure would be nice on Windows to have an equivalent of
>list2cmdline() that works for the shell.

I agree. See issue 13238 for a list of libraries which make is easier to use shell from Python.
History
Date User Action Args
2013-08-04 12:15:47piotr.dobrogostsetnosy: + piotr.dobrogost
messages: + msg194357
2010-06-19 18:36:07chops@demiurgestudios.comsetmessages: + msg108201
2010-06-19 18:16:34exarkunsetmessages: + msg108194
2010-06-19 18:08:50chops@demiurgestudios.comsetmessages: + msg108191
2010-06-19 17:51:28exarkunsetmessages: + msg108189
2010-06-19 17:47:38chops@demiurgestudios.comsetmessages: + msg108188
2010-06-18 20:04:27exarkunsetresolution: fixed -> not a bug

messages: + msg108134
nosy: + exarkun
2008-01-19 22:49:55gregory.p.smithsetstatus: open -> closed
resolution: fixed
messages: + msg60242
2008-01-19 22:39:53gregory.p.smithsetkeywords: + easy
assignee: gregory.p.smith
nosy: + gregory.p.smith
2007-10-18 17:40:54chops@demiurgestudios.comcreate