python 2.7.12 on Linux behaving differently than on Windows

Lew Pitcher lew.pitcher at digitalfreehold.ca
Mon Dec 5 11:41:22 EST 2016


On Monday December 5 2016 10:41, in comp.lang.python, "BartC" <bc at freeuk.com>
wrote:

> On 05/12/2016 15:05, Chris Angelico wrote:
>> On Tue, Dec 6, 2016 at 1:11 AM, BartC <bc at freeuk.com> wrote:
>>>
>>> BTW what does Popen() do when one argument is '*.*'? Will that get
>>> expanded to multiple extra arguments, and at what point will it be
>>> expanded?
>>
>> Nope. Popen is not a shell.
>>
>> It sounds as if you want a nerfed shell. Go ahead! I'm sure one
>> exists. It'll frustrate you no end once you get used to a better
>> shell, though - always does when I find myself on Windows...
> 
> That's not the point I was making.
> 
> Say you have this program a.py:
> 
>    import sys
>    print (sys.argv)
> 
> And let's say there are just 3 files in the current directory: a.py,
> b.py and c.py.
> 
> If run from a Linux shell:
> 
>    python a.py *
> 
> The output is: ['a.py', 'b.py', 'c.py'] or something along those lines
> (there might be two copies of a.py).

And, that's because, before invoking Popen, the SHELL has globbed that '*'
argument into the three filenames and substituted those names where the '*'
was.

If you don't use a shell, then (on Unix), you have to perform the globbing
yourself before invoking Popen.

> 
> Are you saying that if someone executes:
> 
>    subprocess.Popen(["python","a.py", "*"])
> 
> the output will be: ['a.py','*']?
> 
> In that case forget Windows vs. Linux, you now have a program that will
> get command parameters processed differently depending on whether it was
> invoked from a shell or not.

Yes.

> Or a program that sometimes will see "*" as an argument, and sometimes a
> big list of files that merges into all the other arguments.
> 

Yes.

-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request




More information about the Python-list mailing list