This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients anishathalye, eryksun, paul.moore, snoopyjc, steve.dower, tim.golden, zach.ware
Date 2021-12-04.09:08:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638608913.8.0.839347602233.issue40467@roundup.psfhosted.org>
In-reply-to
Content
> it might be nice if it's possible to give some sort of useful 
> warning/error when this happens -- perhaps say that specifying 
> both shell=True and executable="..." isn't supported on Windows?

The `shell` parameter is documented as follows for Windows:

    On Windows with shell=True, the COMSPEC environment variable 
    specifies the default shell. The only time you need to specify 
    shell=True on Windows is when the command you wish to execute is 
    built into the shell (e.g. dir or copy). You do not need
    shell=True to run a batch file or console-based executable.

It wouldn't hurt to clarify that the COMSPEC shell has to support `/c`. This is required by CreateProcessW(), which uses COMSPEC to run BAT and CMD files.

The discussion about using `executable` with `shell` could be extended for Windows. But this would also require new behavior. For example:

Original:

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

Proposed:

    if shell:
        startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
        startupinfo.wShowWindow = _winapi.SW_HIDE
        if executable is not None:
            cmd = executable
        else:
            cmd = os.path.normpath(os.environ.get("COMSPEC", "cmd.exe"))
            if "\\" in cmd:
                executable = cmd
        args = '"{}" /c "{}"'.format(cmd, args)

> if comspec.endswith('sh.exe') or comspec.endswith('sh'):
>     args = '{} -c "{}"'.format (comspec, args)         

sh is not a valid COMSPEC shell. To use sh automatically, subprocess would have to support and prefer the SHELL [1] environment variable in Windows -- and in POSIX for that matter.

---
[1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
History
Date User Action Args
2021-12-04 09:08:33eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, snoopyjc, anishathalye
2021-12-04 09:08:33eryksunsetmessageid: <1638608913.8.0.839347602233.issue40467@roundup.psfhosted.org>
2021-12-04 09:08:33eryksunlinkissue40467 messages
2021-12-04 09:08:33eryksuncreate