Windows Is Not Passing Command Line Arguments to Python Programs Executed from the Shell

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

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

Command-line arguments dropped when running python file directly on Windows

This is a guess, I cannot test right now, but I believe this is what is happening:

  1. you type the name of your python file.
  2. Windows fails to run the file as a program, so…
  3. Windows tries to open the file, using the associated program (kindof with using start).
  4. While doing so, it simply ignores other things on the line, and…
  5. …generates a basic command line for the python
    interpreter to use, featuring just the interpreter itself and the
    target file to open.

Think of what happens when you "run" a text document.

If the command line is not generated correctly, running this command should fix it (replace the path as appropriate):

ftype Python.File=C:\Path\to\python.exe "%1" %*

Notice the %* at the end. If it's amiss, arguments will be dropped.

Can't pass zero arguments to Python program running on Windows command line

You have unneeded double quotes around %* in your registry record. They make Windows pass an empty parameter if there are no arguments. Just remove these quotes.

Run Python scripts from Windows command line, argument not passed

To move the answer to SO (rather than the link in Jon's answer):

Modifying the following two registries so that the arguments are passed along to Python:

HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command
HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

Add %* to the existing "C:\PythonXX\python.exe" "%1", so that the key now looks like: "C:\PythonXX\python.exe" "%1" %*.

Source: http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows/

command line arguments are not retrieved

Remove the argv parameter from main's signature and just use sys.argv[1] :

def main():
print(sys.argv[1])

You also need to call main :

if __name__ == '__main__': 
main()

Execution of Python script with parameter and Windows10 doesn't work

Sorry, after searching with Google instead of hulbee, I found the answer:

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

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

Thanks to mckoss

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

HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

and added a %* to the parameter

Python Command Line Arguments (Windows)

try to run the script using python script.py test.txt, you might have a broken association of the interpreter with the .py extention.



Related Topics



Leave a reply



Submit