python 2.7.12 on Linux behaving differently than on Windows

BartC bc at freeuk.com
Mon Dec 5 10:41:45 EST 2016


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

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.

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

-- 
bartc



More information about the Python-list mailing list