Command Line arguments

Tim Roberts timr at probo.com
Thu Aug 25 03:46:41 EDT 2005


michael <savvyside at aol.com> wrote:

>I have a question about Windows based python (2.4 and later).
>
>For example, if I make a script called test.py like so:
>
>import sys
>print sys.argv
>
>then run it:
>
>python test.py this is a test
>
>I see a list with 
>
>['test.py', 'this', 'is', 'a', 'test']
>
>
>All is good!
>
>BUT...
>
>If i make .py extensions be run as exes (by setting the .py extension to
>be executable with PATHEXT setting in environment variables, the Python
>program will run, but NO arguments are passed!
>
>For example, after setting .py extension to be executable, i get this:
>
>test this is a test
>
>I get ['test.py]. NO arguments are passed. 
>
>NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and
>earlier works FINE.

It is a configuration problem.  Bring up a Command Shell and run the assoc
and ftype commands like this:

  C:\Tmp>assoc .py
  .py=Python.File

  C:\Tmp>ftype Python.File
  Python.File="C:\Apps\Python24\python.exe" "%1" %*

  C:\Tmp>

The KEY part of that is the %* at the end of the Python.File defintion.
That tells the system to insert the rest of the command line parameters at
that point.  If you have ONLY the "%1", the command will run but no
parameters will be forwarded.  If so, you can fix this by typing:

  C:\Tmp>ftype Python.File="C:\Apps\Python24\python.exe" "%1" %*

Substituting your own path, of course.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list