[Tutor] Does python change subprocess based on whether it is run in the interactive shell or not
Mats Wichmann
mats at wichmann.us
Sat Oct 29 14:02:03 EDT 2022
On 10/29/22 11:54, Dennis Lee Bieber wrote:
> On Sat, 29 Oct 2022 14:23:56 +0100, Alan Gauld via Tutor <tutor at python.org>
> declaimed the following:
>
>>
>> Probably not. shell=True simply says to read the command
>> in a shell environment expanding wildcards etc. You don't seem
>> to be using anything that needs shell expansion.
>
> Documentation is a bit confusing...
>
> """
> Changed in version 3.6: args parameter accepts a path-like object if shell
> is False and a sequence containing path-like objects on POSIX.
>
> Changed in version 3.8: args parameter accepts a path-like object if shell
> is False and a sequence containing bytes and path-like objects on Windows.
>
> The shell argument (which defaults to False) specifies whether to use the
> shell as the program to execute. If shell is True, it is recommended to
> pass args as a string rather than as a sequence.
> """
>
> That "is False and a sequence" throws me? I want to read it as "or".
>
> The OP is specifying "cmd" as a string.
Pretty messy, isn't it? These two snips - they're not adjacent in the doc:
> If args is a string, the interpretation is platform-dependent and
described below.
> On Windows, if args is a sequence, it will be converted to a string
in a manner described in Converting an argument sequence to a string on
Windows. This is because the underlying CreateProcess() operates on strings.
So in the Windows case, it always wants a string underneath, and since
that's what was passed by the OP it doesn't seem likely that's "the"
problem.
The further reference that didn't survive the copy/paste is here:
https://docs.python.org/3/library/subprocess.html#converting-argument-sequence
More information about the Tutor
mailing list