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.Popen: impossible to show console window when shell=True #85028

Open
akdor1154 mannequin opened this issue Jun 3, 2020 · 2 comments
Open

subprocess.Popen: impossible to show console window when shell=True #85028

akdor1154 mannequin opened this issue Jun 3, 2020 · 2 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes OS-windows stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@akdor1154
Copy link
Mannequin

akdor1154 mannequin commented Jun 3, 2020

BPO 40851
Nosy @pfmoore, @tjguk, @zware, @eryksun, @zooba, @ZackerySpytz, @akdor1154
PRs
  • gh-85028: Don't set wShowWindow if startupinfo has STARTF_USESHOWWINDOW #20975
  • 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 = None
    created_at = <Date 2020-06-03.04:54:30.637>
    labels = ['3.8', '3.9', '3.10', 'type-feature', 'library', 'OS-windows']
    title = 'subprocess.Popen: impossible to show console window when shell=True'
    updated_at = <Date 2020-06-19.05:53:00.466>
    user = 'https://github.com/akdor1154'

    bugs.python.org fields:

    activity = <Date 2020-06-19.05:53:00.466>
    actor = 'ZackerySpytz'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2020-06-03.04:54:30.637>
    creator = 'akdor1154'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40851
    keywords = ['patch']
    message_count = 2.0
    messages = ['370639', '370641']
    nosy_count = 7.0
    nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'ZackerySpytz', 'akdor1154']
    pr_nums = ['20975']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue40851'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @akdor1154
    Copy link
    Mannequin Author

    akdor1154 mannequin commented Jun 3, 2020

    Hi all,
    It seems impossible to show a new console window with calling subprocess.Popen on windows with shell=True.

    Attempt:
    si = subprocess.STARTUPINFO()
    si.dwFlags = subprocess.STARTF_USESHOWWINDOW
    si.wShowWindow = 5
    proc = Popen(
    cmd, cwd=runFolder, creationflags=subprocess.CREATE_NEW_CONSOLE, shell=True,
    startupinfo=si
    )

    In the current source, it looks like this is due to the block in https://github.com/python/cpython/blob/master/Lib/subprocess.py#L1405 , which unreservedly wipes wShowWindow even if I have provided it.

    Testing on Python 3.6 but I am assuming this affects all versions.

    @akdor1154 akdor1154 mannequin added 3.7 (EOL) end of life 3.10 only security fixes 3.8 only security fixes 3.9 only security fixes OS-windows labels Jun 3, 2020
    @eryksun
    Copy link
    Contributor

    eryksun commented Jun 3, 2020

    I think you have the right idea for improving the behavior here. It should skip setting wShowWindow if startupinfo already has the flag STARTF_USESHOWWINDOW. For example:

        if shell:
            comspec = os.environ.get("COMSPEC", "cmd.exe")
            args = '{} /c "{}"'.format (comspec, args)
            if not startupinfo.dwFlags & _winapi.STARTF_USESHOWWINDOW:
                startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = _winapi.SW_HIDE

    @eryksun eryksun added stdlib Python modules in the Lib dir type-feature A feature request or enhancement and removed 3.7 (EOL) end of life labels Jun 3, 2020
    @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
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes OS-windows stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant