Skip to content

commands.getoutput() does not work on windows #59278

Closed

Description

@pfedin
mannequin
BPO 15073
Nosy @amauryfa, @bitdancer
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 2012-06-15.08:38:47.693>
    created_at = <Date 2012-06-15.05:53:20.256>
    labels = ['type-bug', 'OS-windows']
    title = 'commands.getoutput() does not work on windows'
    updated_at = <Date 2012-06-15.13:30:41.712>
    user = 'https://bugs.python.org/pfedin'

    bugs.python.org fields:

    activity = <Date 2012-06-15.13:30:41.712>
    actor = 'p.fedin'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-06-15.08:38:47.693>
    closer = 'amaury.forgeotdarc'
    components = ['Windows']
    creation = <Date 2012-06-15.05:53:20.256>
    creator = 'p.fedin'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 15073
    keywords = []
    message_count = 4.0
    messages = ['162844', '162874', '162894', '162897']
    nosy_count = 3.0
    nosy_names = ['amaury.forgeotdarc', 'r.david.murray', 'p.fedin']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '10197'
    type = 'behavior'
    url = 'https://bugs.python.org/issue15073'
    versions = ['Python 2.7']

    Activity

    1. pfedin commented on Jun 15, 2012

      pfedinmannequin
      MannequinAuthor

      commands.getoutput() is broken on Windows. The issue has been detected in v2.7.2, but still persists in v2.7.3:
      --- cut ---

      Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import commands;
      >>> print commands.getoutput("dir");
      '{' is not recognized as an internal or external command,
      operable program or batch file.
      >>>
      --- cut 

      The error message comes from cmd.exe. Looks like Python tries to feed native Windows shell with UNIX-style commands sequence in {...}.
      I believe this is very simple to fix, please take a look at it. Some our internal software croaks because of this.

    2. amauryfa commented on Jun 15, 2012

      @amauryfa
      Contributor
      The documentation http://docs.python.org/library/commands.html
      prominently says "Platforms: Unix".  This module does not work on Windows.
      You should really use the subprocess module:
      >>> import subprocess
      >>> output = subprocess.check_output("dir", shell=True)
    3. bitdancer commented on Jun 15, 2012

      @bitdancer
      Member

      Hmm. Maybe bpo-10197 should be reclassified as an enhancement...

    4. changed the title [-]commands.getoutput() is broken[/-] [+]commands.getoutput() does not work on windows[/+] on Jun 15, 2012
    5. pfedin commented on Jun 15, 2012

      pfedinmannequin
      MannequinAuthor

      I see it's deprecated and dropped, but anyway, why not to fix it to work on Windows? From 10197 i see the fix is quite simple, and there is lots of legacy code i believe.

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

      OS-windowstype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions