Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subprocess.list2cmdline doesn't do pipe symbols #45641

Closed
chopsdemiurgestudioscom mannequin opened this issue Oct 18, 2007 · 9 comments
Closed

subprocess.list2cmdline doesn't do pipe symbols #45641

chopsdemiurgestudioscom mannequin opened this issue Oct 18, 2007 · 9 comments
Assignees
Labels
easy OS-windows type-bug An unexpected behavior, bug, or error

Comments

@chopsdemiurgestudioscom
Copy link
Mannequin

BPO 1300
Nosy @gpshead

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/gpshead'
closed_at = <Date 2008-01-19.22:49:55.178>
created_at = <Date 2007-10-18.17:40:54.939>
labels = ['easy', 'type-bug', 'invalid', 'OS-windows']
title = "subprocess.list2cmdline doesn't do pipe symbols"
updated_at = <Date 2013-08-04.12:15:47.503>
user = 'https://bugs.python.org/chopsdemiurgestudioscom'

bugs.python.org fields:

activity = <Date 2013-08-04.12:15:47.503>
actor = 'piotr.dobrogost'
assignee = 'gregory.p.smith'
closed = True
closed_date = <Date 2008-01-19.22:49:55.178>
closer = 'gregory.p.smith'
components = ['Windows']
creation = <Date 2007-10-18.17:40:54.939>
creator = 'chops@demiurgestudios.com'
dependencies = []
files = []
hgrepos = []
issue_num = 1300
keywords = ['easy']
message_count = 9.0
messages = ['56534', '60242', '108134', '108188', '108189', '108191', '108194', '108201', '194357']
nosy_count = 4.0
nosy_names = ['gregory.p.smith', 'exarkun', 'chops@demiurgestudios.com', 'piotr.dobrogost']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1300'
versions = ['Python 2.5']

@chopsdemiurgestudioscom
Copy link
Mannequin Author

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.

@chopsdemiurgestudioscom chopsdemiurgestudioscom mannequin added OS-windows type-bug An unexpected behavior, bug, or error labels Oct 18, 2007
@gpshead gpshead added the easy label Jan 19, 2008
@gpshead gpshead self-assigned this Jan 19, 2008
@gpshead
Copy link
Member

gpshead commented Jan 19, 2008

fixed in trunk r60115 (2.6).

@gpshead gpshead closed this as completed Jan 19, 2008
@exarkun
Copy link
Mannequin

exarkun mannequin commented Jun 18, 2010

I reverted r60115 from trunk (2.7) in r82075 and from py3k in r82076.

@exarkun exarkun mannequin added the invalid label Jun 18, 2010
@chopsdemiurgestudioscom
Copy link
Mannequin Author

Why is this bug invalid?

@exarkun
Copy link
Mannequin

exarkun mannequin commented Jun 19, 2010

See the commit message for r82075 and the discussion on bpo-8972 and bpo-7839.

@chopsdemiurgestudioscom
Copy link
Mannequin Author

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"'?

@exarkun
Copy link
Mannequin

exarkun mannequin commented Jun 19, 2010

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 bpo-7839.

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.

@chopsdemiurgestudioscom
Copy link
Mannequin Author

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.

@piotrdobrogost
Copy link
Mannequin

piotrdobrogost mannequin commented Aug 4, 2013

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 bpo-13238 for a list of libraries which make is easier to use shell from Python.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant