os.system not working calling sikuli scripts from the command prompt

Asked by bcaine0

Im trying to make a basic function to glob all of my sikuli scripts and run them in order. This is to make a standard main for a testing framework.

While this isn't necessarily a sikuli syntax issue, it is an issue with calling sikuli from the command prompt.

My script relies on os.system to call the functions. But the same exact string that I type into the cmd prompt that works there does not work with os.system. Heres the important syntax (I have the correct imports not shown)

files = glob.glob('./tests/*.sikuli')
if len(files) is 0:
    raise TestHelper.TestError('ERROR: no test files found')
for xfile in files:
    logging.debug('Running test: ' + str(xfile[1:]))
    os.system('"C:/Program Files/Sikuli X/Sikuli-IDE.exe" -r ' + '"' + os.getcwd()+ xfile[1:] + '"')

To step you through my code, here is whats going on.

It goes to the tests/ directory and finds all folders with .sikuli
This gets put into a list called files.
We do a quick check if there are files in this list, if not, toss a custom error.
then we loop through the list of files, getting a single file per time through.
We log whats going on
Then we call os.system to call sikuli via the command prompt. The code inside of the parenthesis gives the following output:
"C:/Program Files/Sikuli X/Sikuli-IDE-w.bat" -r "C:\MY_DIRECTORIES\SikTest/tests\CPRS Testing.sikuli"

You will notice the different \ after DIRECTORIES and before SikTest. This however does not cause an issue doing it manually and is needed for glob to work.

So I guess what I am asking is whether anyone else has experienced problems using os.system to call a sikuli script via the method described to call it via the command prompt, and if anyone has a workaround or can tell me what I am doing wrong.

Thanks

Question information

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

Might be,that the blank in the .sikuli folder name makes the problem.

Revision history for this message
bcaine0 (bcaine0) said :
#2

Thanks for the quick response

Thats the problem I originally ran into, however the quotes on either side of the directory towards my .sikuli folder should take care of that (and do when doing it manually via the cmd prompt).

If i take my exact method inside the os.system parentheses and instead print it to the screen, and then type this exact command via the command prompt manually it works.

It may just be python related and not sikuli related, but this same method and code (with the necessary modifications) work for python files used in another testing suite.

Thats why it makes me wonder if it has something to do with the method that is used to call sikuli via the command prompt.

If no one has any ideas on whether this may be sikuli related or not, then i'll start playing with other methods to replace os.system

Thanks

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

Yes, than it might really be a problem of the Jython implementation of os.system (which has other restrictions against the Python version of os.system).

I never use this, but os.popen or the subprocess module, because they have the option to access the output of an issued command.

The other option would be, to pack all the specifics into a command file and call this with only the one parameter: sikuli folder name.

I will check os.system the next days on my Win7

Revision history for this message
bcaine0 (bcaine0) said :
#4

Alright that makes sense. I forgot about discrepancies between Jython and Python. Ill play around with os.popen and subprocess.

Thanks

Can you help with this problem?

Provide an answer of your own, or ask bcaine0 for more information if necessary.

To post a message you must log in.