How to pass command line arguments to script

Asked by Bryan Rasmussen

I am on mac running sikuli IDE 1.0.1
I have a script with the following in it:

from sys import *

browsername = "Firefox"
if len(sys.argv) > 0:
  browsername = sys.argv[0]
else:
    stack = traceback.extract_stack(limit = 2)
    print '[Error]: ' + str(stack[0][1])

If I remove the if len(sys.argv) and so forth through the else then my script works

If I remove the else but still have the if then the script still fails (so even if there is some problem with my attempt to get the stack trace it is not that problem that concerns me (especially as I only added that trying to figure out what is wrong with the sys.argv stuff.

the rest of my script works fine (automating firefox, going and clicking on some links, looking for part of a form to show up etc. ) so I am not including it, What I really want to know is how to get the value of the first command line argument or if there is no command line argument don't evaluate the part of the script inside of that if.

Thanks,
Bryan

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
obiwan-92 (obiwan-92) said :
#1

Hello,

It will helpful to tell us what do you want to do.
Anyway, I think you have some problem with your code, because "len(sys.argv) > 0" is always true.
Sys.argv contains at least your Python script, so there no need to check if it is less than 0.

I will please to give you a correction but like I already said, I have no idea of what you want to do.
Tell me and I will help you ;)

Regards.

Can you help with this problem?

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

To post a message you must log in.