Passing command line argument using sikuli-script.jar does not work

Asked by bengalih

I'm sorry to ask this because I see several similar questions but I have read them and still am not able to get a result.

Executing from command prompt on Windows:

C:\Users\myuser> java -jar "c:\Program Files (x86)\Sikuli X\sikuli-script.jar" "c:\script\test.sikuli" hello

Sikuli script:

import sys
print sys.argv[1]

does not seem to print hello. It seems to print what I would expect sys.argv[0] which is the path...that gets printed with either [0] or [1].

Maybe I am not doing this correctly, as I don't know python well. Can you assist in how I can get the parameter "hello" into the script?

thanks!

Question information

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

This was discussed in https://answers.launchpad.net/sikuli/+question/194353, but the request bug was not posted by the user yet, so I do it now.

from comment #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 as a workaround, you have to use sikuli-ide.jar instead.

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

Using sikuli-ide.jar instead of sikuli-script.jar would definitely solve the problem because you can use the --args parameter there.

C:\Users\myuser> java -jar "c:\Program Files (x86)\Sikuli X\sikuli-ide.jar" "c:\script\test.sikuli" --args hello

I don't know how well the sikuli-script.jar handles command line arguments.
For the purpose of debugging you can print the whole argumentlist with "print sys.argv".

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

damn RaiMan was faster :D

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

@ j-the-k
LOL, had already some coffee after wake-up ;-)

Revision history for this message
bengalih (bengalih) said :
#5

Rai's syntax was correct (need the -r).

Unfortunately using the ide.bat instead of script.bat means that any error output gets displayed via a pop-up GUI rather than within the cmd console. I do not know if there are any other side-effects to using one over the other, but I suppose I can live with this for now. Would be nice if additional cmd line support can be implemented in the future.

thx.

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

the -s parameter does what you want.

Revision history for this message
Harish Main (harish-main) said :
#7

Even iam trying same but i dont have any sikuli-ide.jar? in myc:\sikulix folder

I have C:\sikulix\ folder with following files and i have selected Option 2 while installation.
SikuliX-1.1.0-SetupLog.jar
sikulixapi.jar
sikulixsetup-1.1.0.jar
sikulixtessdata.jar

Where i can find sikuli-ide.jar?

Thanks

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

see: http://sikulix.com/quickstart

to read about setup, what you get and what to use for what