Running script from command line with parameter

Asked by Rom

I have a script that automates application installation. When my script contains a hard-coded fileName, it works without problem. However, when I made my script accepts argument, it fails as App.focus is on the cmd.exe. I also noticed this problem when I try SikuliSharp to call my scripts. Is there any work-around for this? below is part of my script.

import sys
name = "absetup.exe" // this works
name = sys.argv[1] // this didn't

s = Screen()
app = App(name)

if not app.window():
    app.open(5)
    wait(10)

app.focus()

.. other instructions here...

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

Not sure what you are doing (what is SikuliSharp?).

How to get parameters from commandline into a Sikuli(X) script:
http://sikulix-2014.readthedocs.io/en/latest/faq/010-command-line.html

Revision history for this message
Rom (romcab) said :
#2

Hi RaiMan,

thanks for the quick response, appreciate it.

I created scripts to automate installation of certain applications like firefox, avbrowser, etc. SikuliSharp is a C# wrapper that provides an interface to call sikuli scripts. Anyway, I can actually get the parameter. However, what i noticed is that app.open did not open the installer. Based from the log, App.focus : [2148: cmd.exe], it should be the absetup.exe as it is what I'm trying to open.

runsikulix.cmd -r my-script.sikuli --args 'absetup.exe'

import sys
#name = "absetup.exe"
name = sys.argv[1]
print(name)

s = Screen()
myApp = App(name)

if not myApp.window():
    myApp.open(10)
    s.wait(10)

myApp.focus()
wait(5)
click("Install.png")
s.wait(10)
click("CheckBox.png")
s.wait(1)
click("Finish.png")

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

ok, then the problem might be, that on Windows the app name not really is the application name, but the title of a window.
So you might try with a window title of your installer, to check wether it is open and to focus and just use App.open() to start your installer in case.

Something like that:

myApp = App("some valid window title of the installer")

if not myApp.window():
    App.open("absetup.exe")
    while not myApp.window(): wait(1)

myApp.focus()

What version of Sikuli(X) are you using?

Revision history for this message
Rom (romcab) said :
#4

 i followed your suggestion but still no luck. I'm using the latest version - 1.1.0. I have a work-around in mind, which is to create a text file containing the whole command - containing the filename. I will then execute it via process. however, i'm still looking for a better way.

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

1.1.0 is not really the latest version.

You might give 1.1.1 a try (http://sikulix.com) which will surely be final the next 2 weeks.

Revision history for this message
Rom (romcab) said :
#6

Is it different from sikuli2? I'm actually waiting for it.

Anyway, thank you. I will surely wait for the next version.

On Sep 9, 2016 8:08 PM, "RaiMan" <email address hidden>
wrote:

> Your question #389068 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/389068
>
> RaiMan proposed the following answer:
> 1.1.0 is not really the latest version.
>
> You might give 1.1.1 a try (http://sikulix.com) which will surely be
> final the next 2 weeks.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/389068/+confirm?answer_id=4
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/389068
>
> You received this question notification because you asked the question.
>

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

SikuliX 2 is a complete rewrite and will only be available as beta later this year.

Bug fixes and minor improvements are in 1.1.1 currently and there will surely be a 1.1.2 during the next 12 months.
Somewhen next year when version 2 has proved to be backwards compatible, I will stop version 1.1.x.

Can you help with this problem?

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

To post a message you must log in.