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.
I also configure the register info manually.
So what should I do to solve this problem? Your help will be very important to me.
-
I expect you might need to logout-login to reload the file association information after manual editing.Mathieu CAROFF– Mathieu CAROFF2018-11-16 22:15:50 +00:00Commented Nov 16, 2018 at 22:15
-
2I don't understand very well how you run your script when using the python shell. Could you describe it more precisely?Mathieu CAROFF– Mathieu CAROFF2018-11-16 22:21:29 +00:00Commented Nov 16, 2018 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 %* (stackoverflow.com/a/38612907/6451573)Jean-François Fabre– Jean-François Fabre ♦2018-11-16 22:24:16 +00:00Commented Nov 16, 2018 at 22:24
Add a comment
|