Skip to content

Support bytes for subprocess.Popen() #48286

Closed

Description

@vstinner
BPO 4036
Nosy @loewis, @vstinner, @abadger, @briancurtin
Dependencies
  • bpo-4035: Support bytes for os.exec*()
  • Files
  • subprocess-bytes.patch: Support bytes in the POSIX version of subprocess
  • subprocess-bytes-2.patch
  • 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 = None
    closed_at = <Date 2010-04-20.23:51:31.248>
    created_at = <Date 2008-10-03.23:45:14.700>
    labels = ['type-feature', 'library']
    title = 'Support bytes for subprocess.Popen()'
    updated_at = <Date 2010-04-20.23:51:31.247>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2010-04-20.23:51:31.247>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-04-20.23:51:31.248>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2008-10-03.23:45:14.700>
    creator = 'vstinner'
    dependencies = ['4035']
    files = ['11742', '16423']
    hgrepos = []
    issue_num = 4036
    keywords = ['patch']
    message_count = 12.0
    messages = ['74284', '74305', '74505', '75366', '100357', '100360', '100363', '100365', '100366', '100367', '100376', '103796']
    nosy_count = 4.0
    nosy_names = ['loewis', 'vstinner', 'a.badger', 'brian.curtin']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue4036'
    versions = ['Python 3.1']

    Activity

    1. vstinner commented on Oct 3, 2008

      @vstinner
      MemberAuthor

      subprocess doesn't support bytes for the "args" argument.

      • On Windows, subprocess._execute_child() converts args to a string
        if it was a list
      • On UNIX, subprocess._execute_child() converts args to a list if
        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.

    2. loewis commented on Oct 4, 2008

      loewismannequin
      Mannequin

      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.

    3. vstinner commented on Oct 8, 2008

      @vstinner
      MemberAuthor

      Oops, I attached the wrong patch :-/

    4. vstinner commented on Oct 30, 2008

      @vstinner
      MemberAuthor

      @loewis: My patch only changes the behaviour of the POSIX version of
      subprocess, Windows version is unchanged.

    5. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on May 17, 2009
    6. vstinner commented on Mar 3, 2010

      @vstinner
      MemberAuthor

      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?

    7. vstinner commented on Mar 4, 2010

      @vstinner
      MemberAuthor

      (oops, the issue is still open)

    8. briancurtin commented on Mar 4, 2010

      @briancurtin
      Member

      The tests pass on OS X, but fail on Windows. I'll look into it.

    9. vstinner commented on Mar 4, 2010

      @vstinner
      MemberAuthor

      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?

    10. briancurtin commented on Mar 4, 2010

      @briancurtin
      Member

      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.

    11. briancurtin commented on Mar 4, 2010

      @briancurtin
      Member

      What is the right encoding to convert a string to bytes
      for the file system?

      sys.getfilesystemencoding()?

    12. loewis commented on Mar 4, 2010

      loewismannequin
      Mannequin

      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.

    13. vstinner commented on Apr 20, 2010

      @vstinner
      MemberAuthor

      subprocess accepts byte string in program arguments in py3k, so the issue can be closed.

      I opened other issues for the other arguments:

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions