简体   繁体   English

将参数从批处理文件发送到Jython / Python

[英]Send Arguments from Batch File to Jython/Python

I wrote a Sikuli script (Jython) to test a webpage. 我编写了一个Sikuli脚本(Jython)来测试网页。 The script contains multiple tests in it, which means that when one kills sikuli, the ones after it will not run. 该脚本中包含多个测试,这意味着当一个脚本杀死sikuli时,它将无法运行。 To fix this, I'd like to instead call each test via a batch file. 为了解决这个问题,我想改为通过批处理文件调用每个测试。 So it is currently set up similar to this: 因此,目前它的设置与此类似:

tests = [test1, test2, test3, test4]

for test in tests:
  run test

Obviously, that is a simplified version... so what I'd like to do is convert the list into 4 batch files. 显然,这是一个简化的版本...所以我要做的就是将列表转换成4个批处理文件。 The first batch file would call the script with test1 as an argument; 第一个批处理文件将使用test1作为参数调用脚本。 the second would send test2 as an argument, etc. I could then create another batch file to iterate through them. 第二个将发送test2作为参数,依此类推。然后,我可以创建另一个批处理文件来迭代它们。 However, I don't know how to communicate between a batch file and jython, other than just plainly running the script. 但是,除了仅仅运行脚本之外,我不知道如何在批处理文件和jython之间进行通信。

This question refers to both the batch file and jython scripts - I'm assuming you have to do something special in each. 这个问题涉及批处理文件和jython脚本-我假设您必须在每个脚本中做一些特别的事情。

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks. 谢谢。

Question is not 100% clear for me. 问题对我来说不是100%清楚的。 I assume this is the answer: 我认为这就是答案:

First of all, you need to pass some arguments to Sikuli script started from batch file using --args option, for example: 首先,您需要使用--args选项将一些参数传递给从批处理文件开始的Sikuli脚本,例如:

YourPath\runIDE.cmd -r YourPath\YourScript.sikuli --args test1 test2 someOtherOption

Second of all, you must receive it in a script using sys.argv variable. 其次,您必须使用sys.argv变量在脚本中接收它。 It would work the same in either Python or Jython. 它在Python或Jython中都可以工作。 Code sample: 代码示例:

import sys
print sys.argv

for a in sys.argv:
    if a=="test1":
        print "Do something"
    elif a=="test2":
        print "Do something else"

https://docs.python.org/2/library/sys.html#sys.argv https://docs.python.org/2/library/sys.html#sys.argv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM