Skip to content

Subprocess.getstatusoutput Fails Executing 'dir' Command on Windows #50058

Closed

Description

@mrwizard82d1
BPO 5808
Nosy @orsenthil, @ssbarnea
Superseder
  • bpo-10197: subprocess.getoutput fails on win32
  • 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 2009-04-21.15:56:03.642>
    created_at = <Date 2009-04-21.15:49:32.930>
    labels = ['type-bug', 'invalid']
    title = "Subprocess.getstatusoutput Fails Executing 'dir' Command on Windows"
    updated_at = <Date 2012-08-20.03:57:25.826>
    user = 'https://bugs.python.org/mrwizard82d1'

    bugs.python.org fields:

    activity = <Date 2012-08-20.03:57:25.826>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-04-21.15:56:03.642>
    closer = 'mrwizard82d1'
    components = []
    creation = <Date 2009-04-21.15:49:32.930>
    creator = 'mrwizard82d1'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 5808
    keywords = []
    message_count = 6.0
    messages = ['86242', '86243', '91005', '91011', '91013', '110424']
    nosy_count = 4.0
    nosy_names = ['orsenthil', 'ssbarnea', 'mrwizard82d1', 'matthieu.labbe']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = '10197'
    type = 'behavior'
    url = 'https://bugs.python.org/issue5808'
    versions = []

    Activity

    1. mrwizard82d1 commented on Apr 21, 2009

      mrwizard82d1mannequin
      MannequinAuthor

      When attempting to use the subprocess.getstatusoutput() function on
      Windows, I noticed an unusual error message:
      "'{' is not recognized as an internal or external command,
      operable program or batch file."

      When the output contained this message, the status was always 256.

      From the interactive prompt, I performed the following:
      Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit
      (Intel)] on
      win32
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import subprocess
      >>> cmdline = 'dir'
      >>> (status, output) = subprocess.getstatusoutput(cmdline)
      >>> status
      256
      >>> output
      "'{' is not recognized as an internal or external command,\noperable
      program or
      batch file."
      >>>

      I think this is an error (but it is possible I misunderstand the
      documentation for the function :) .)

    2. mrwizard82d1 commented on Apr 21, 2009

      mrwizard82d1mannequin
      MannequinAuthor

      Oops: user error. The manual states that subprocess.getstatusoutput() is
      only open under Unix. Somehow :) I missed this note.

      Sorry for wasting bandwidth.

    3. ssbarnea commented on Jul 28, 2009

      ssbarneamannequin
      Mannequin

      Also the same issue does apply for command.getstatusoutput in Python 2.6.

      Maybe this bug should be reopened and solved by adding a platform check
      in the module. Also the documentation does not specify what would be the
      right multiplatform alternative.

      Anyway, the current result it's clearly not the expected behavior and
      does not give any hint regarding the source of the problem or possible
      solutions.

    4. orsenthil commented on Jul 28, 2009

      @orsenthil
      Member

      sorin:

      You meant the commands module, correct?
      It is well documented in the commands reference:
      http://docs.python.org/library/commands.html

      • It is applicable to unix only.
      • the getstatusoutput is moved to subprocess in 3x.
    5. ssbarnea commented on Jul 28, 2009

      ssbarneamannequin
      Mannequin

      If I made a patch that will raise an error if you include commands
      module under Windows will you include it - this will safe others time.

    6. matthieulabbe commented on Jul 16, 2010

      matthieulabbemannequin
      Mannequin

      I think this is a bug: The doc says "Availability: UNIX." but it is *available* under Windows and gives an unexpected error message.

      I see several way to fix this:

      1. Fix the doc: "Supported only on UNIX. Behavior on other platforms is undefined."
      2. Make subprocess.getstatusoutput (and subprocess.getoutput) unavailable on non-supported platforms. (Same behavior as the 'os' module.)
      3. Make these convenience functions multiplatform using subprocess.Popen.

      I think the best thing to do is #3. What do you think?

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

      type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions