Posts: 14
Threads: 3
Joined: Mar 2017
Mar-20-2017, 03:22 PM
(This post was last modified: Mar-20-2017, 03:22 PM by hary.)
Hi
I'm trying to launch a .exe program with a python3.6 script.
I usualy launch my program.exe using command line "cmd" with 5 arguments as follow :
C:\Users\Harold>"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe" 200 1.5 20 80 100
I've tried differnt things with no success !
WIth the 5 arguments:
# python3
# launch_SESAME.py launch SESAME
import subprocess
subprocess.Popen([r"cmd"])
subprocess.Popen([r'"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe" 500 1.5 20 80 200']) Error: Traceback (most recent call last):
File "C:\Python35-32\launch_SESAME.py", line 9, in <module>
subprocess.Popen([r'"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe" 500 1.5 20 80 200'])
File "C:\Python35-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Python35-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
PermissionError: [WinError 5] Accès refusé
Microsoft Windows [version 10.0.14393]
(c) 2016 Microsoft Corporation. Tous droits réservés.
With no arguments : the program behave the same way I would have launched it with cmd command line without providing the arguments !
import subprocess
subprocess.Popen([r"cmd"])
subprocess.Popen([r'C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe']) Error: EGSesame
Generateur de creneaux via Instrunet pour obturateur Sesame, normalises DNI.
Alterne entre 2 phases ou positions du Sesame avec un profil triangle. EG 27 octobre 2016
UTILISATION: EGSesame [gradient_chauffe duree_cyclage niveau1 niveau2 gradient_niveaux]
gradient_chauff : gradient en pourcents par minute, jusqu'au niveau de phase le plus bas. Ex: 500
Duree du cyclage : en heure. Ex: 1.5 pour 1h30
Niveaux des phases: exprime en pourcent du Sesame, de 0.0 a 100.0 (ouvert).
gradient_niveaux : gradient en pourcents par minute, entre les 2 niveaux. Ex: 100
ATTENTION: Pas ou mauvais arguments donnes, reglages par defaut.
Microsoft Windows [version 10.0.14393]
(c) 2016 Microsoft Corporation. Tous droits réservés.
I'm a total beginner.
Any advice or link welcome.
Posts: 1,150
Threads: 42
Joined: Sep 2016
Hello,
usually this happens because program wasn't launched with administrator rights. So if you can, run the Python script as administrator.
Posts: 331
Threads: 2
Joined: Feb 2017
Mar-20-2017, 03:46 PM
(This post was last modified: Mar-20-2017, 04:44 PM by zivoni.)
You cant execute directly program and parameters in one string with Popen - it tries to run command named "program parameter" and there is no such program. You can either split parameters and use ['program', 'parameter/parameters',... 'parameter'] or let python execute entire string within shell/cmd with parameter shell=True. Latter one is easier to use (or abuse).
Output: In [2]: subprocess.Popen("/bin/echo 10")
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
....
FileNotFoundError: [Errno 2] No such file or directory: '/bin/echo 10'
In [3]: subprocess.Popen(["/bin/echo", "10"])
10
Out[3]: <subprocess.Popen at 0x7fa1f1d8a940>
In [4]: subprocess.Popen("/bin/echo 10", shell=True)
Out[4]: 10
You are not catching output of your program, if you want to do it, you can use Popen with stdout=subprocess.PIPE or run you program with subprocess.check_output().
Posts: 14
Threads: 3
Joined: Mar 2017
Mar-20-2017, 04:41 PM
(This post was last modified: Mar-20-2017, 04:51 PM by hary.)
(Mar-20-2017, 03:27 PM)j.crater Wrote: Hello,
usually this happens because program wasn't launched with administrator rights. So if you can, run the Python script as administrator.
No change to run the script as administrator !
(Mar-20-2017, 03:46 PM)zivoni Wrote: You cant execute directly program and parameters in one string with Popen - it tries to run command named "program parameter" and there is no such program. You can either split parameters and use ['program', 'parameter/parameters',... 'parameter'] or let python execute entire string within shell/cmd with parameter shell=True. Latter one is easier to use (or abuse).
Output: In [2]: subprocess.Popen("/bin/echo 10")
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
....
FileNotFoundError: [Errno 2] No such file or directory: '/bin/echo 10'
In [3]: subprocess.Popen(["/bin/echo", "10"])
10
Out[3]: <subprocess.Popen at 0x7fa1f1d8a940>
In [4]: subprocess.Popen("/bin/echo 10", shell=True)
Out[4]: 10
You are not catching output of your program, if you want to do it, you can use Popen with stdout=subprocess.PIPE or run you program with subprocess.check_output().
Sorry but as I said, I'm a total beginner and what you say is not really helpfull as not intelligible for me.
subprocess.Popen("/bin/echo 10") and
subprocess.Popen(["/bin/echo", "10"]) and
subprocess.Popen("/bin/echo 10", shell=True) give me all the same error !
Posts: 331
Threads: 2
Joined: Feb 2017
Those was just examples of command with parameter and as it was linux command, it couldn't work for you on windows machine.
What i ment was to try either
subprocess.Popen(r'"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe" 500 1.5 20 80 200', shell=True) or
subprocess.Popen([r'"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe"', "500", "1.5", "20", "80", "200"]) (if i got your command/parameters right)
Posts: 687
Threads: 37
Joined: Sep 2016
(Mar-20-2017, 05:03 PM)zivoni Wrote: Those was just examples of command with parameter and as it was linux command, it couldn't work for you on windows machine.
What i ment was to try either
subprocess.Popen(r'"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe" 500 1.5 20 80 200', shell=True) or
subprocess.Popen([r'"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe"', "500", "1.5", "20", "80", "200"]) (if i got your command/parameters right)
You've got a bunch of extra quotes around the executable name:
subprocess.Popen([r'C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe', "500", "1.5", "20", "80", "200"])
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Posts: 331
Threads: 2
Joined: Feb 2017
Mar-20-2017, 05:37 PM
(This post was last modified: Mar-20-2017, 05:37 PM by zivoni.)
I remembered that ages ago commands with spaces in name were run in windows terminal like "C:\Program Files\dir name\boo.exe" , so I kept OP's double quotes :), but yes, here it is different thing (probably).
Posts: 14
Threads: 3
Joined: Mar 2017
@ zivoni
get the following errors
Error: Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:\Python35-32\launch_SESAME.py ==================
Traceback (most recent call last):
File "C:\Python35-32\launch_SESAME.py", line 11, in <module>
subprocess.Popen(r'"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe" 500 1.5 20 80 200', shell=True)
File "C:\Python35-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Python35-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
>>>
Error: Traceback (most recent call last):
File "C:\Python35-32\launch_SESAME.py", line 12, in <module>
subprocess.Popen([r'"C:\Program Files (x86)\EGSesameTriangle\Debug\EGSesameTriangle.exe"', "500", "1.5", "20", "80", "200"])
File "C:\Python35-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Python35-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
PermissionError: [WinError 5] Accès refusé
Posts: 687
Threads: 37
Joined: Sep 2016
For the second thing, see my remark about the extra quotes.
When having such errors, make it simple. Change the code to start some known executable (say, notepad.exe). Once you have got that working, change to your executable, then use your parameters...
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
|