python - How to run a batch file in background from Sikuli? -
how run batch file in background sikuli?
environment: winxp, python 2.7, sikuli r930.
let’s assume have simple batch file startnotepad.bat contains 1 line:
start notepad
i start batch file using os.system method python script:
import os os.system("startnotepad.bat") os.system("d:\\newdir\\startnotepad.bat") print("hello notepad")#displayed while 2 instances of notepad running
when start python script behaves want – notepad windows opened in background, python script continues after calling batch files. start batch file using os.system in sikuli script , here comes trouble. sikuli script looks this:
import os os.system("d:\\newdir\\startnotepad.bat") print("hello notepad")#displayed after notepad closed
when start sikuli ide there errors:
[info] sikuli vision engine loaded. [info] windows utilities loaded. [info] vdictproxy loaded. [error] stopped [error] linia 2 zawiera blad [error] informacja o bledzie: traceback (most recent call last): file "c:\docume~1\*********\locals~1\temp\sikuli-tmp2989271839024887193.py", line 2, in os.system("d:\\newdir\\startnotepad.bat") file "c:\program files\sikuli x\sikuli-script.jar\lib\subprocess.py", line 456, in call file "c:\program files\sikuli x\sikuli-script.jar\lib\subprocess.py", line 751, in __init__ file "c:\program files\sikuli x\sikuli-script.jar\lib\subprocess.py", line 1236, in _execute_child typeerror: unsupported operand type(s) +: 'nonetype' , 'list'
ok,it not big deal because use executable sikuli script anyway. however, in case of non gui mode doesn’t behave intended – sikuli script waits until notepad closed.
why os.system works differently in case of pure python , sikuli? guess because sikuli has own python interpreter. can behavior configured somehow? there workaround that?
the behaviour won’t same python runtime sikuli java. sikuli uses jython, , jython java written using python syntax.
according documentation of os.system(command) blocks return return code form spawned sub shell. (http://docs.python.org/2/library/os.html#os.system)
it possible in python , java default shell states might different , 1 returns when shell command complete , other waits handles close.
ideally want non-blocking subprocess.
you can ether use pythons subprocess.popen or sikuli’s app.open() achieve
Comments
Post a Comment