sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #02778
Re: [Question #156909]: MAC : Issue with exit code from sikuli for RC2
Question #156909 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/156909
Status: Needs information => Answered
RaiMan proposed the following answer:
Since I always wanted the new subprocess.Popen, I made the following
test (Mac OS X 10.6):
-- The Sikuli script testexit.sikuli:
Settings.InfoLogs = False
if len(sys.argv) > 0:
p = 1 if sys.argv[0].count('.sikuli')>0 else 0
print "Sikuli script returns:", sys.argv[p]
exit(sys.argv[p])
else:
exit()
-- The Python script (Python 2.6.1):
import subprocess
cmd = ['/Applications/Sikuli-IDE.app/sikuli-ide.sh', '-r']
script = ['/Users/rhocke/Downloads/19_Sikuli/testexit.sikuli']
print "***** Running with kernel (shell=False)"
p = subprocess.Popen(cmd+script, shell=False)
p.wait()
print "given: () --- returned:", p.returncode
p = subprocess.Popen(cmd+script+['0'], shell=False)
p.wait()
print "given: (0) --- returned:", p.returncode
p = subprocess.Popen(cmd+script+['1'], shell=False)
p.wait()
print "given: (1) --- returned:", p.returncode
print "***** Running with shell (shell=True)"
cmd = '/Applications/Sikuli-IDE.app/sikuli-ide.sh -r '
script = '/Users/rhocke/Downloads/19_Sikuli/testexit.sikuli '
p = subprocess.Popen(cmd+script, shell=True)
p.wait()
print "given: () --- returned:", p.returncode
p = subprocess.Popen(cmd+script+'0', shell=True)
p.wait()
print "given: (0) --- returned:", p.returncode
p = subprocess.Popen(cmd+script+'1', shell=True)
p.wait()
print "given: (1) --- returned:", p.returncode
--- Output produced:
***** Running with kernel (shell=False)
given: () --- returned: 0
Sikuli script returns: 0
given: (0) --- returned: 0
Sikuli script returns: 1
given: (1) --- returned: 1
***** Running with shell (shell=True)
given: () --- returned: 0
Sikuli script returns: 0
given: (0) --- returned: 0
Sikuli script returns: 1
given: (1) --- returned: 1
I deleted manually the 3 startup [info] messages of Sikuli!
--- Conclusion: In both possible modes (with or without shell)
everything is as expected.
--- some comments:
-- sys.argv to the Sikuli script is different in the 2 modes:
shell=False: first parameter is in sys.argv[0] (no script name available)
shell=True: first parameter is in sys.argv[1] (script name in 0) as expected
So this has to be evaluated in a Sikuli script, that should run in all modes.
--- if neither subprocess.poll() nor subprocess.wait() is used after subprocess.Popen(), subprocess.returncode does not reflect the returncode of this last issued subprocess.Popen(), until either subprocess.poll() or subprocess.wait() is used
(this might be the problem in this case)
--- I think, there is no need to use the mode shell=True to run a Sikuli
script, since the calling interface can be handled much easier and more
generally than with shell=False.
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.