1

I am using Windows 10 and I wrote a python script to open an external .exe program. The python version is Python 3.6.
I use subprosee.Popen(command, shell = True) to run command. (If I did not inclue the shell=True parameter it won't work properly)
There is a sentence print(sys.argv). When I run command like >python program.py arg1 arg2 in windows command prompt, a python shell will be started and it got shown twice. In Command Prompt is shows:
['program.py' 'arg1' 'arg2']
However, in python shell it shows:
['program.py']
Which means the arguments are not passed into python script properly. How should I solve this? I have searched some hints online and someone mentions the association configuration. I did the following thing:
assoc .py=Python.File ftype Python.File="C:\Anaconda3\python.exe" "%1" %*
but the weird thing is that although I can find Python.File="C:\Anaconda3\python.exe" "%1" %* by ftype | findstr -i python, it shows File type 'Python.File' not found or no open command associated with it. when I type ftype Python.File.
enter image description here I also configure the register info manually. r So what should I do to solve this problem? Your help will be very important to me.

PRMoureu
  • 12,817
  • 6
  • 38
  • 48
Somebody X
  • 51
  • 1
  • 2
  • I expect you might need to logout-login to reload the file association information after manual editing. – Mathieu CAROFF Nov 16 '18 at 22:15
  • 2
    I don't understand very well how you run your script when using the python shell. Could you describe it more precisely? – Mathieu CAROFF Nov 16 '18 at 22:21
  • ftype and assoc always seemed unreliable to me. What I did is associate .py to the python exe, then find the entry in the registry and add %1 %* (https://stackoverflow.com/a/38612907/6451573) – Jean-François Fabre Nov 16 '18 at 22:24

0 Answers0