How to pass arguments to Sikuli script run without the IDE

Asked by Andrew P

I have set up an automation framework that launches Sikuli scripts on multiple remote virtual machines in parallel, then collects the results.

Since the scripts are the same, they somehow need to know that they are running under different scenarios (use different login credentials, etc.). I would like to be able to pass command line parameters to Sikuli scripts.

Right now, there's a runner (essentially a webserver) that receives requests over HTTP with script names, launches them, collects their console output, and returns that in an XML format for the mothership to process and analyze.

Here's the command that the runner uses to launch scripts:

java -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -jar "%SIKULI_HOME%\sikuli-script.jar" "[SCRIPT_DIR]\scriptName.sikuli" 2>&1

When I try to supply arguments to it using the --arg switch provided in the documentation, sikuli-script.jar seems to treat them as the names of sikuli scripts to run. Here's an example. The testArg.sikuli script simply prints out the content of sys.argv:

===============
File: testArg.sikuli
===============

import sys

print "I will print all values in argv\n"

for a in sys.argv:
    print a
===============

Then I launch it with this command:

java -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -jar "%SIKULI_HOME%\sikuli-script.jar"--arg firstargument testArgv.sikuli" 2>&1

This is the console output I get:

===============
[error] Can't run this Sikuli script: --arg
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
 at java.lang.String.substring(Unknown Source)
 at org.sikuli.script.ScriptRunner.getPyFrom(ScriptRunner.java:106)
 at org.sikuli.script.ScriptRunner.runPython(ScriptRunner.java:100)
 at org.sikuli.script.SikuliScript.main(SikuliScript.java:111)
[error] Can't run this Sikuli script: firstargument
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
 at java.lang.String.substring(Unknown Source)
 at org.sikuli.script.ScriptRunner.getPyFrom(ScriptRunner.java:106)
 at org.sikuli.script.ScriptRunner.runPython(ScriptRunner.java:100)
 at org.sikuli.script.SikuliScript.main(SikuliScript.java:111)
[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.
I will print all values in argv

. estArgv.sikuli
--arg
firstargument
.\testArgv.sikuli
===============

It seems like the testArgv.sikuli script does get a hold of command line parameters in sys.argv, but the jar archive still treats them as sikuli script names.

Any ideas on how to tackle this? 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
j (j-the-k) said :
#1

java -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -jar "%SIKULI_HOME%\sikuli-script.jar"--arg firstargument testArgv.sikuli" 2>&1

If you used this command, I can see three mistakes at first sight:
It should be --args, not --arg and there's only one quote sign at the end of this commend. You can leave the quotes and do something like --args arg1 arg2 arg3 or you use quotes like --args "arg1 arg2 arg3". Both works with my scripts, but only one quote is a syntax problem.
The reason why this command does not work is probably also because you have to put the testname before the --args paremter as it is shown here: http://sikuli.org/docx/faq/010-command-line.html

So you should try
java -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -jar "%SIKULI_HOME%\sikuli-script.jar" testArgv.sikuli --args "firstargument" 2>&1

I hope this helped.

Revision history for this message
j (j-the-k) said :
#2

*command
*parameter
sorry for typos

Revision history for this message
Andrew P (a-ap-u) said :
#3

Sorry for being sloppy with typing. I did indeed run the command without the quotes and with the right switch. I also just ran the command you suggested and the problem is still there: sikuli-script.jar seems to treat anything after it as names of other scripts:

========================
C:\uitests\sikuli>java -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -jar "%SIKULI_HOME%\sikuli-script.jar" testArgv.sikuli --args "firstargument" 2>&1
[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.
I will print all values in argv

testArgv.sikuli
--args
firstargument
[error] Can't run this Sikuli script: --args
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(Unknown Source)
        at org.sikuli.script.ScriptRunner.getPyFrom(ScriptRunner.java:106)
        at org.sikuli.script.ScriptRunner.runPython(ScriptRunner.java:100)
        at org.sikuli.script.SikuliScript.main(SikuliScript.java:111)
[error] Can't run this Sikuli script: firstargument
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(Unknown Source)
        at org.sikuli.script.ScriptRunner.getPyFrom(ScriptRunner.java:106)
        at org.sikuli.script.ScriptRunner.runPython(ScriptRunner.java:100)
        at org.sikuli.script.SikuliScript.main(SikuliScript.java:111)

C:\uitests\sikuli>
================

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

This --args option seems only to work, when using sikuli-ide.jar instead of sikuli-script.jar.

This works for me:

C:\uitests\sikuli>java -jar "%SIKULI_HOME%\sikuli-ide.jar" -r testArgv.sikuli --args "firstargument" 2>&1

So it might be worth a request bug: want to have same behavior on --args for sikuli-script.jar

Revision history for this message
j (j-the-k) said :
#5

Right, I didn't notice you used sikuli-script.jar instead of sikuli-ide.jar.
@RaiMan what exactly is the difference between the two?
I always use sikuli-ide.sh

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

@ j-the-k
--- sikuli-script.jar
contains all kernel java classes, the c-based modules and supporting stuff, that make up the features of Sikuli. On top it contains all the Jython related stuff including the Jython interpreter Java classes to run a Python script.

--- sikuli-ide.jar
contains the IDE GUI, written in Java. It can be used from command line (as in the Sikuli-IDE.bat, Sikuli-IDE-w.bat or sikuli-ide.sh) to open the IDE, open the IDE with a given script or run it (parameter -r), without showing the IDE GUI.
to run a script, internally the features of sikuli-scritpt.jar are used.

Revision history for this message
Human (bob-igo) said :
#7

On Linux, I'm able to invoke Sikuli this way to add parameters that the script can use:

sikuli-ide -r ./myscript.sikuli -args "argshere"

Does this behavior differ by platform?

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

@ Human (or even mankind ;-)
When asking questions as comments to questions, you should subscribe to the question (done it for you ;-) or post your own question.

see: http://sikuli.org/docx/faq/010-command-line.html#how-to-run-sikuli-from-command-line
only the call method differ (Sikuli-IDE.bat recommended on Windows).

Can you help with this problem?

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

To post a message you must log in.