Unable to run .exe file with environment variable

Asked by cat123

Hi RaiMan,

I wrote a new version of my previous bug. This time I don't use the os.environ but subprocess.call.

Thanks! I very much appreciate your helpfulness in this forum.

I don't want to hard code the path to the .exe file I want to test in my .sikuli file. Our scheduler will run the .exe file through the settings of environment variables, without hard coding.
And we don't want to change the path setting, but only run through an environment variable.
I wrote the following script, it works on python but not on sikuli. Would you have any alternatives\workarounds?

#MyApp environment variable is created in system in variables under System\Advanced Settings
# My file path is: C:\2014-03-07(20h30)\bin\MyApp.exe
#We can run the following script on Python, it's OK
#We can also run "%MyApp%" on command prompt, it's OK.

from sikuli import*
import os, sys
import subprocess

os.system('echo %MyApp%') #We have the path to environment variable. [GOOD]
subprocess.call('"%MyApp%"', shell = True) #But we can't run it [BAD]

We have the following error message (not pasted the whole message):

'C:\2014-03-07' is not recognized as an internal or external command,
operable program or batch file.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.text.FlowView$FlowStrategy.layoutRow(Unknown Source)
at javax.swing.text.FlowView$FlowStrategy.layout(Unknown Source)
at javax.swing.text.FlowView.layout(Unknown Source)
at javax.swing.text.BoxView.setSize(Unknown Source)
at javax.swing.text.BoxView.updateChildSizes(Unknown Source)
at javax.swing.text.BoxView.setSpanOnAxis(Unknown Source)
at javax.swing.text.BoxView.layout(Unknown Source)
at javax.swing.text.BoxView.setSize(Unknown Source)
at javax.swing.text.BoxView.updateChildSizes(Unknown Source)
at javax.swing.text.BoxView.setSpanOnAxis(Unknown Source)
at javax.swing.text.BoxView.layout(Unknown Source)
at javax.swing.text.BoxView.setSize(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.modelToView(Unknown Source)
at

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

this is a question

Revision history for this message
Best RaiMan (raimund-hocke) said :
#2

With shell=True, on Windows the given command string is given to CMD.EXE, which expects the string to be an executable command and be quoted according to the rules of CMD.EXE.

If the executable filename contains special characters, that have a meaning when parsing a command line - like your ( ... ) - then the complete command has to be in double-double-quotes:

subprocess.call('""%MyApp%""', shell = True)

... but IMHO this should work also:

subprocess.call(os.environ["MYAPP"])

Revision history for this message
cat123 (jazzycat2013) said :
#3

Thanks RaiMan, that solved my question.