1

In Windows console if I execute this script (test.py):

import sys
print(sys.argv)

like:

>python test.py my args

I get expected output:

['test.py', 'my', 'args']

but if I call it directly, like this:

>test.py my args

I get: ['C:\\temp\\test.py'] output, as if I didn't pass any arguments. Why?

FYI:

>assoc | findstr .py=
.py=Python.File

>ftype Python.File
Python.File=C:\Python35\python.exe "%1" %*
vedar
  • 483
  • 8
  • 15
  • See this thread here: http://stackoverflow.com/questions/2640971/windows-is-not-passing-command-line-arguments-to-python-programs-executed-from-t – nbryans Jun 15 '16 at 02:00
  • 1
    cmd's `assoc` and `ftype` show the system definitions from `HKLM\Software\Classes`, not per-user settings from `HKCU\Software\Classes` and not the defaults defined in either `Classes` key for `SystemFileAssociations` and `Applications`. They also don't show the *user's choice* among these settings, which is stored in `HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts`. The user's choice is what `ShellExecuteEx` actually uses. Configure this in Explorer, with the "open with" dialog (choose another / always use) or the control panel "Default Programs". – Eryk Sun Jun 15 '16 at 07:12
  • 1
    Also, `Python.File` for a standard 3.5 installation should use the py launcher, which handles Unix-style shebangs for scripts that require other versions of Python. If the launcher is installed for all users, it's in the `%SystemRoot%` directory (e.g. "C:\Windows"), for which the command template would be `C:\Windows\py.exe "%1" %*`. – Eryk Sun Jun 15 '16 at 07:18

1 Answers1

0

Similar to the discussion here, you want to make sure the command key is set properly. On my copies of Windows 10, I found I had the command reg set to "C:\Python27\python.exe" "%1" %* in 2 places

HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command
HKEY_CLASSES_ROOT\Python.File\shell\open\command

I guess the first thing to do would be to check these 2 keys.

Community
  • 1
  • 1
nbryans
  • 1,507
  • 17
  • 24