0

Q1: I´m calling a Python script with input arguments from a cmd terminal:

python hello.py arg1 arg2

Python.exe and hello.py are both in my PATH, arg1 and arg2 are filenames in my current directory, everything executes well if I give the full path to hello.py. Is it possible to omit the full path so that the PATH is searched for hello.py?

Q2: I tried to make the following call:

hello.py arg1 arg2

The PATH is searched for hello.py which opens with python.exe as the default program, but I can´t get it to accept the arguments. Is it possible to include the variables this way?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Jugge
  • 1
  • Could update you post with your code please? – julian salas Feb 11 '17 at 00:30
  • Running hello.py should work, but the .py file association is misconfigured. In the "open with" menu select the entry to choose another app. In the dialog enable the option to always use the selected app. In the list of apps, choose the one named "Python" (not "python.exe"). In this menu, never choose to browse for an executable when you're configuring the association for a scripting language like .py files. Windows doesn't set it up correctly to get command-line arguments. Use a pre-configured ProgId like "Python" (`Python.File` in the registry) that's created by the installer. – Eryk Sun Feb 11 '17 at 12:11
  • Thanks eryksun, you pointed me in the right way. I had to edit a string in the registry. – Jugge Feb 12 '17 at 02:45
  • Since this may help someone else, here is my solution. I set python.exe to be the default application for *.py files. The problem with this is that it does not pass additional arguments to the python executable. To solve this I went to **Computer\HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command** in the registry and added %\* to the string value i.e. **"\python.exe" "%1" %\*** – Jugge Feb 12 '17 at 02:59

0 Answers0