You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this should be deferred to 3.1. I'm not sure how much
consistency across platforms is desirable, however, using strings is
surely the better choice on Windows. I could sympathize with providing
bytes support only on POSIX, but I'm sure others will disagree.
Oops, I realized that the second test is just useless. The argument is str, not bytes. I wanted to test Popen(bytes, shell=True). What is the right encoding to convert a string to bytes for the file system?
The list2cmdline function checks spaces, tabs, etc in line 521 of subprocess.py. In your first test case, it ends up checking if a string is contained in a bytes object, which is a TypeError for the str not supporting the buffer API.
Would it be acceptable to just add "arg = str(arg)" right under the for loop? That fixes it for me, not sure of the preferred way to go about it.
Activity
vstinner commentedon Oct 3, 2008
subprocess doesn't support bytes for the "args" argument.
if it was a list
it's a string
If shell=True, _execute_child() adds a prefix to the arguments.
I don't know if subprocess should accept bytes in a command line.
Attached patch fixes POSIX version of subprocess to support bytes.
See also related issue bpo-4035.
loewis commentedon Oct 4, 2008
I think this should be deferred to 3.1. I'm not sure how much
consistency across platforms is desirable, however, using strings is
surely the better choice on Windows. I could sympathize with providing
bytes support only on POSIX, but I'm sure others will disagree.
vstinner commentedon Oct 8, 2008
Oops, I attached the wrong patch :-/
vstinner commentedon Oct 30, 2008
@loewis: My patch only changes the behaviour of the POSIX version of
subprocess, Windows version is unchanged.
vstinner commentedon Mar 3, 2010
os.exec*() now accept bytes thanks to the PEP-383: see issue bpo-4035.
I updated my patch: it now includes tests \o/ It works on Linux. Can someone test it on Windows and/or Mac OS X?
vstinner commentedon Mar 4, 2010
(oops, the issue is still open)
briancurtin commentedon Mar 4, 2010
The tests pass on OS X, but fail on Windows. I'll look into it.
vstinner commentedon Mar 4, 2010
Oops, I realized that the second test is just useless. The argument is str, not bytes. I wanted to test Popen(bytes, shell=True). What is the right encoding to convert a string to bytes for the file system?
briancurtin commentedon Mar 4, 2010
The list2cmdline function checks spaces, tabs, etc in line 521 of subprocess.py. In your first test case, it ends up checking if a string is contained in a bytes object, which is a TypeError for the str not supporting the buffer API.
Would it be acceptable to just add "arg = str(arg)" right under the for loop? That fixes it for me, not sure of the preferred way to go about it.
briancurtin commentedon Mar 4, 2010
sys.getfilesystemencoding()?
loewis commentedon Mar 4, 2010
On Windows, command lines shouldn't need to be encoded in any encoding. Instead, the unicode string should be passed to the system call as-is.
vstinner commentedon Apr 20, 2010
subprocess accepts byte string in program arguments in py3k, so the issue can be closed.
I opened other issues for the other arguments: