0

I've got some Python scripts, which I used from cmd line or batch files or with drag&drop to do useful things.

Example:

makeMyWork.py "hi" 77

Now I got Win10 :-(

Windows10 doesn't forward the parameters to my python scripts. I have to write:

c:\Python27\python.exe makeMyWork.py "hi" 77

A lot of automatism isn't working anymore now. I started to change some important batch-files, but that's a lot of work. I want have back, the old behavior.

What can I do now ?

rundekugel
  • 1,118
  • 1
  • 10
  • 23
  • We cannot help you unless you post what is inside `makeMyWork.py` – Jason Mar 15 '16 at 16:12
  • 2
    Windows is not linux. Put the python location in your `$PATH$` environment variable and you'll only have to type "`python makeMyWork.py`" – Goodies Mar 15 '16 at 16:20
  • It was working with WinXp,7,8 without extending `$PATH$`. – rundekugel Mar 15 '16 at 16:46
  • @Jason: Please read my question first. It's about the command line params are not passed to the python script. It's not about the content of the python script. – rundekugel Sep 02 '19 at 11:14
  • @Goodies: I've no problems of executing a script with python.exe. It's about the paramaters – rundekugel Sep 02 '19 at 11:14

2 Answers2

1

Step 1: Right click on a python script and use open-with to open with your python.exe

Step 2: Change registry so that running your python script from command line will cause python.exe to read individual arguments, and not to combine all arguments into a single string.

Note that due to Windows limits, only the first 8 arguments are available individually. Downside is os.argv will contains empty strings appended when less than 8 arguments. The alternative is to use %* which would join all arguments with spaces but make it available as sys.argv1

The fix is to add a code: while sys.argv[-1] == '': del sys.argv[-1]

Use Regedit, or save below to a .reg file, edit the path, then run it.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command] @=""C:\Users\andrewm\anaconda3\python.exe" "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "

[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command] @=""C:\Users\andrewm\anaconda3\python.exe" "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "

regedit

andrewm
  • 11
  • 2
  • instead of : "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" it's simpler, and uses all available params: " \"%1\" %*" – rundekugel Sep 29 '22 at 08:35
0

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

Community
  • 1
  • 1
rundekugel
  • 1,118
  • 1
  • 10
  • 23