Windows没有将命令行参数传递给从shell执行的Python程序

时间:2021-12-05 04:44:52

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

如果我尝试直接将它们作为Windows命令shell中的可执行命令执行,那么我无法将命令行参数传递给Python程序。例如,如果我有这个程序(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:\Python25\python.exe" "%1" %*
Python.File="C:\Python25\python.exe" "%1" %*
Python.NoConFile="C:\Python25\pythonw.exe" "%1" %*

8 个解决方案

#1


85  

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_ROOT\Python.File\shell\open\command):

我想我解决了这个问题。由于某种原因,注册表中存在第二个位置(除了存储在HKEY_CLASSES_ROOT \ Python.File \ shell \ open \ command中的文件关联所示):

[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command]
@="\"C:\\Python25\\python.exe\" \"%1\" %*"

This seems to be the controlling setting on my system. The registry setting above adds the "%*" to pass all arguments to python.exe (it was missing in my registry for some reason).

这似乎是我系统的控制设置。上面的注册表设置添加“%*”以将所有参数传递给python.exe(由于某种原因,它在我的注册表中丢失)。

#2


13  

My setting was under yet another registry key, HKEY_CLASSES_ROOT\py_auto_file. The other keys mentioned also existed, but Windows was using this one for some reason.

我的设置是另一个注册表项HKEY_CLASSES_ROOT \ py_auto_file。提到的其他密钥也存在,但Windows出于某种原因使用了这个。

#3


8  

For Python 3.3 on Windows 7, my setting was under another registry key; the key I changed to make the arguments get passed was

对于Windows 7上的Python 3.3,我的设置是在另一个注册表项下;我改变的关键是让参数得到通过

HKEY_USERS\S-1-5-21-3922133726-554333396-2662258059-1000_Classes\py_auto_file\shell\open\command

HKEY_USERS \ S-1-5-21-3922133726-554333396-2662258059-1000_Classes \ py_auto_file \壳\开放\命令

It was "C:\Python\Python33\python.exe" "%1". I only appended %* to it. The key's value is now "C:\Python\Python33\python.exe" "%1" %*.

它是“C:\ Python \ Python33 \ python.exe”“%1”。我只附加了%*。键的值现在是“C:\ Python \ Python33 \ python.exe”“%1”%*。

I had several (at least five) other keys with the value "C:\Python\Python33\python.exe" "%1", but this is the one I changed that made it work.

我有几个(至少五个)其他键的值为“C:\ Python \ Python33 \ python.exe”“%1”,但这是我更改的那个使它工作。

#4


2  

To make it working for me, I had to use the registry path:

为了让它适合我,我不得不使用注册表路径:

HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

and added a %*

并增加了%*

#5


1  

Interesting. Works here using python 2.6 and Windows XP (5.1.2600):

有趣。使用python 2.6和Windows XP(5.1.2600)在这里工作:

C:\Documents and Settings\hbrown>python test.py foo
['test.py', 'foo']

C:\Documents and Settings\hbrown>test.py foo
['C:\\Documents and Settings\\hbrown\\test.py', 'foo']

C:\Documents and Settings\hbrown>test foo
['C:\\Documents and Settings\\hbrown\\test.py', 'foo']

C:\Documents and Settings\hbrown>type test.py
import sys
print sys.argv 

C:\Documents and Settings\hbrown>echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PY 

C:\Documents and Settings\hbrown>assoc .py
.py=Python.File

#6


1  

Here are .reg files to fix for Python 3.6, 2.7 and Anaconda3:

以下是修复Python 3.6,2.7和Anaconda3的.reg文件:

python-3.6.0.reg

蟒蛇,3.6.0.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"


[HKEY_CLASSES_ROOT\py_auto_file]

[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.File]
@="Python File"

[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"

[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Python36\\DLLs\\pyc.ico"

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"

[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"

python-2.7.0.reg

蟒蛇,2.7.0.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"


[HKEY_CLASSES_ROOT\py_auto_file]

[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.File]
@="Python File"

[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"

[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Python27\\DLLs\\pyc.ico"

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"

[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"

ananconda3.reg (change username)

ananconda3.reg(更改用户名)

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"


[HKEY_CLASSES_ROOT\py_auto_file]

[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.File]
@="Python File"

[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"

[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\pyc.ico"

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"

[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"

#7


0  

Your program associations for .py files might be messed up. Just re-associate .py files with your python executable.

你的.py文件的程序关联可能搞砸了。只需将.py文件与python可执行文件重新关联即可。

Right click a .py file > Open with > Choose default program ... > [find C:\PythonXY\python.exe]

右键单击.py文件>打开>选择默认程序...> [找到C:\ PythonXY \ python.exe]

#8


0  

I checked all registry keys with python.exe and py_auto_file and made them point to my current python installation including th %* at the end that passes arguments. They were quite a few:

我使用python.exe和py_auto_file检查了所有注册表项,并使它们指向我当前的python安装,包括传递参数的末尾的%*。他们不少:

  • HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command:

    HKEY_CLASSES_ROOT \应用程序\ python.exe \壳\开放\命令:

    • org: "C:\miniconda3\python.exe" "%1" "%*"
    • 组织:“C:\ miniconda3 \ python.exe”“%1”“%*”
    • changed: "C:\Python35\python.exe" "%1" "%*"
    • 更改:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

    HKEY_CLASSES_ROOT \ py_auto_file \壳\开放\命令

    • org: "C:\Program Files\Sublime Text 3\sublime_text.exe" "%1"
    • 组织:“C:\ Program Files \ Sublime Text 3 \ sublime_text.exe”“%1”
    • changed: "C:\Python35\python.exe" "%1" "%*"
    • 更改:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_CURRENT_USER\Software\Classes\py_auto_file\shell\open\command

    HKEY_CURRENT_USER \ Software \ Classes下\ py_auto_file \壳\开放\命令

    • org: "C:\Python35\python.exe" "%1" "%*"
    • org:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_USERS\S-1-5-21-2621213409-1291422344-4183577876-2165\Software\Classes\py_auto_file\shell\open\command

    HKEY_USERS \ S-1-5-21-2621213409-1291422344-4183577876-2165 \ Software \ Classes下\ py_auto_file \壳\开放\命令

    • org: "C:\Python35\python.exe" "%1" "%*"
    • org:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_USERS\S-1-5-21-2621213409-1291422344-4183577876-2165_Classes\py_auto_file\shell\open\command

    HKEY_USERS \ S-1-5-21-2621213409-1291422344-4183577876-2165_Classes \ py_auto_file \壳\开放\命令

    • org: "C:\Python35\python.exe" "%1" "%*"
    • org:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_CLASSES_ROOT\Applications\pythonw.exe\shell\open\command

    HKEY_CLASSES_ROOT \应用程序\ pythonw.exe \壳\开放\命令

    • org: "C:\Python34\pythonw.exe" "%1"
    • org:“C:\ Python34 \ pythonw.exe”“%1”
    • changed: "C:\Python35\pythonw.exe" "%1" "%*"
    • 更改:“C:\ Python35 \ pythonw.exe”“%1”“%*”
  • HKEY_CURRENT_USER\Software\Classes\Applications\python.exe\shell\open\command

    HKEY_CURRENT_USER \ Software \ Classes下\应用程序\ python.exe \壳\开放\命令

    • org: "C:\Python35\python.exe" "%1" "%*"
    • org:“C:\ Python35 \ python.exe”“%1”“%*”

But that didn't do the job for me. I had to change my default python application as well.

但那并没有为我做好工作。我也必须更改我的默认python应用程序。

Windows没有将命令行参数传递给从shell执行的Python程序

As one can see I have 3 Python versions installed. It is impossible to see which is which here so I tried all three of them as my default python application. Eventually I was able to get my script arguments with one of these three.

可以看出我安装了3个Python版本。不可能看到哪个在这里,所以我尝试了所有这三个作为我的默认python应用程序。最终我能够用这三个中的一个得到我的脚本参数。

#1


85  

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_ROOT\Python.File\shell\open\command):

我想我解决了这个问题。由于某种原因,注册表中存在第二个位置(除了存储在HKEY_CLASSES_ROOT \ Python.File \ shell \ open \ command中的文件关联所示):

[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command]
@="\"C:\\Python25\\python.exe\" \"%1\" %*"

This seems to be the controlling setting on my system. The registry setting above adds the "%*" to pass all arguments to python.exe (it was missing in my registry for some reason).

这似乎是我系统的控制设置。上面的注册表设置添加“%*”以将所有参数传递给python.exe(由于某种原因,它在我的注册表中丢失)。

#2


13  

My setting was under yet another registry key, HKEY_CLASSES_ROOT\py_auto_file. The other keys mentioned also existed, but Windows was using this one for some reason.

我的设置是另一个注册表项HKEY_CLASSES_ROOT \ py_auto_file。提到的其他密钥也存在,但Windows出于某种原因使用了这个。

#3


8  

For Python 3.3 on Windows 7, my setting was under another registry key; the key I changed to make the arguments get passed was

对于Windows 7上的Python 3.3,我的设置是在另一个注册表项下;我改变的关键是让参数得到通过

HKEY_USERS\S-1-5-21-3922133726-554333396-2662258059-1000_Classes\py_auto_file\shell\open\command

HKEY_USERS \ S-1-5-21-3922133726-554333396-2662258059-1000_Classes \ py_auto_file \壳\开放\命令

It was "C:\Python\Python33\python.exe" "%1". I only appended %* to it. The key's value is now "C:\Python\Python33\python.exe" "%1" %*.

它是“C:\ Python \ Python33 \ python.exe”“%1”。我只附加了%*。键的值现在是“C:\ Python \ Python33 \ python.exe”“%1”%*。

I had several (at least five) other keys with the value "C:\Python\Python33\python.exe" "%1", but this is the one I changed that made it work.

我有几个(至少五个)其他键的值为“C:\ Python \ Python33 \ python.exe”“%1”,但这是我更改的那个使它工作。

#4


2  

To make it working for me, I had to use the registry path:

为了让它适合我,我不得不使用注册表路径:

HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

and added a %*

并增加了%*

#5


1  

Interesting. Works here using python 2.6 and Windows XP (5.1.2600):

有趣。使用python 2.6和Windows XP(5.1.2600)在这里工作:

C:\Documents and Settings\hbrown>python test.py foo
['test.py', 'foo']

C:\Documents and Settings\hbrown>test.py foo
['C:\\Documents and Settings\\hbrown\\test.py', 'foo']

C:\Documents and Settings\hbrown>test foo
['C:\\Documents and Settings\\hbrown\\test.py', 'foo']

C:\Documents and Settings\hbrown>type test.py
import sys
print sys.argv 

C:\Documents and Settings\hbrown>echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PY 

C:\Documents and Settings\hbrown>assoc .py
.py=Python.File

#6


1  

Here are .reg files to fix for Python 3.6, 2.7 and Anaconda3:

以下是修复Python 3.6,2.7和Anaconda3的.reg文件:

python-3.6.0.reg

蟒蛇,3.6.0.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"


[HKEY_CLASSES_ROOT\py_auto_file]

[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.File]
@="Python File"

[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"

[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Python36\\DLLs\\pyc.ico"

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"

[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"

python-2.7.0.reg

蟒蛇,2.7.0.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"


[HKEY_CLASSES_ROOT\py_auto_file]

[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.File]
@="Python File"

[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"

[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Python27\\DLLs\\pyc.ico"

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"

[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"

ananconda3.reg (change username)

ananconda3.reg(更改用户名)

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"


[HKEY_CLASSES_ROOT\py_auto_file]

[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.File]
@="Python File"

[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"

[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\pyc.ico"

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"


[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"

[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"

#7


0  

Your program associations for .py files might be messed up. Just re-associate .py files with your python executable.

你的.py文件的程序关联可能搞砸了。只需将.py文件与python可执行文件重新关联即可。

Right click a .py file > Open with > Choose default program ... > [find C:\PythonXY\python.exe]

右键单击.py文件>打开>选择默认程序...> [找到C:\ PythonXY \ python.exe]

#8


0  

I checked all registry keys with python.exe and py_auto_file and made them point to my current python installation including th %* at the end that passes arguments. They were quite a few:

我使用python.exe和py_auto_file检查了所有注册表项,并使它们指向我当前的python安装,包括传递参数的末尾的%*。他们不少:

  • HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command:

    HKEY_CLASSES_ROOT \应用程序\ python.exe \壳\开放\命令:

    • org: "C:\miniconda3\python.exe" "%1" "%*"
    • 组织:“C:\ miniconda3 \ python.exe”“%1”“%*”
    • changed: "C:\Python35\python.exe" "%1" "%*"
    • 更改:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

    HKEY_CLASSES_ROOT \ py_auto_file \壳\开放\命令

    • org: "C:\Program Files\Sublime Text 3\sublime_text.exe" "%1"
    • 组织:“C:\ Program Files \ Sublime Text 3 \ sublime_text.exe”“%1”
    • changed: "C:\Python35\python.exe" "%1" "%*"
    • 更改:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_CURRENT_USER\Software\Classes\py_auto_file\shell\open\command

    HKEY_CURRENT_USER \ Software \ Classes下\ py_auto_file \壳\开放\命令

    • org: "C:\Python35\python.exe" "%1" "%*"
    • org:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_USERS\S-1-5-21-2621213409-1291422344-4183577876-2165\Software\Classes\py_auto_file\shell\open\command

    HKEY_USERS \ S-1-5-21-2621213409-1291422344-4183577876-2165 \ Software \ Classes下\ py_auto_file \壳\开放\命令

    • org: "C:\Python35\python.exe" "%1" "%*"
    • org:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_USERS\S-1-5-21-2621213409-1291422344-4183577876-2165_Classes\py_auto_file\shell\open\command

    HKEY_USERS \ S-1-5-21-2621213409-1291422344-4183577876-2165_Classes \ py_auto_file \壳\开放\命令

    • org: "C:\Python35\python.exe" "%1" "%*"
    • org:“C:\ Python35 \ python.exe”“%1”“%*”
  • HKEY_CLASSES_ROOT\Applications\pythonw.exe\shell\open\command

    HKEY_CLASSES_ROOT \应用程序\ pythonw.exe \壳\开放\命令

    • org: "C:\Python34\pythonw.exe" "%1"
    • org:“C:\ Python34 \ pythonw.exe”“%1”
    • changed: "C:\Python35\pythonw.exe" "%1" "%*"
    • 更改:“C:\ Python35 \ pythonw.exe”“%1”“%*”
  • HKEY_CURRENT_USER\Software\Classes\Applications\python.exe\shell\open\command

    HKEY_CURRENT_USER \ Software \ Classes下\应用程序\ python.exe \壳\开放\命令

    • org: "C:\Python35\python.exe" "%1" "%*"
    • org:“C:\ Python35 \ python.exe”“%1”“%*”

But that didn't do the job for me. I had to change my default python application as well.

但那并没有为我做好工作。我也必须更改我的默认python应用程序。

Windows没有将命令行参数传递给从shell执行的Python程序

As one can see I have 3 Python versions installed. It is impossible to see which is which here so I tried all three of them as my default python application. Eventually I was able to get my script arguments with one of these three.

可以看出我安装了3个Python版本。不可能看到哪个在这里,所以我尝试了所有这三个作为我的默认python应用程序。最终我能够用这三个中的一个得到我的脚本参数。