Windows is not passing command line arguments to Python programs executed from the shell

Posted on

Question :

Windows is not passing command line arguments to Python programs executed from the shell

I’m having trouble getting command line arguments passed to Python programs if I try to execute them directly as executable commands from a Windows command shell. For example, if I have this program (test.py):

import sys
print "Args: %r" % sys.argv[1:]

And execute:

>test foo
Args: []

as compared to:

>python test.py foo
Args: ['foo']

My configuration has:

PATH=...;C:python25;...
PATHEXT=...;.PY;....

>assoc .py
.py=Python.File

>ftype | grep Python
Python.CompiledFile="C:Python25python.exe" "%1" %*
Python.File="C:Python25python.exe" "%1" %*
Python.NoConFile="C:Python25pythonw.exe" "%1" %*

Asked By: mckoss

||

Answer #1:

I think I solved this. For some reason there is a SECOND place in the registry (besides that shown by the file associations stored in HKEY_CLASSES_ROOTPython.Fileshellopencommand):

[HKEY_CLASSES_ROOTApplicationspython.exeshellopencommand]
@=""C:\Python25\python.exe"" ""%1"" %*""

Leave a Reply

Your email address will not be published.