简体   繁体   English

从sikuli传递参数执行.py脚本

[英]Execute .py script from sikuli passing arguments

I have a code to be executed in Sikuli, and I want to call an external Python Script to analyze the data from a generated file. 我有一个要在Sikuli中执行的代码,我想调用一个外部Python脚本来分析生成文件中的数据。

I have tried directly importing the .py file, subprocess.call(), subprocess.Popen() and execfile() 我已经尝试过直接导入 .py文件, subprocess.call(), subprocess.Popen()execfile()

I have two main problems: 我有两个主要问题:

  • Firstly, I need to pass some arguments to the python script (specifically the path of the file to analyze [str] and the test number [int]). 首先,我需要将一些参数传递给python脚本(特别是要分析[str]和测试编号[int]的文件的路径)。
  • Secondly, my .py script uses libraries such as matplotlib.pyplot or numpy that cannot be executed by Jython. 其次,我的.py脚本使用了Jython无法执行的库,例如matplotlib.pyplotnumpy

I am lost already, after trying all the possibilities I could think of. 在尝试了所有可能的方法之后,我已经迷失了。 What should work best? 什么应该最有效? Thank you in advance. 先感谢您。

You can pass arguments to a Sikuli script as easy as that: 您可以像这样简单地将参数传递到Sikuli脚本:

C:\Sikulix\runScript.cmd -r Tests\Test.sikuli --arg argVal

then you can access it like this: 那么您可以像这样访问它:

print sys.argv[1]

where 1 is the order of an argument as they appear in command line. 其中1是自变量在命令行中显示的顺序。

You can use execfile like this: 您可以像这样使用execfile

execfile("C:\SikuliX\Tests\Test.py")

the issue with this however is that execfile runs a Python file by loading it and not as a script. 但是,这样做的问题是execfile 通过加载而不是脚本来运行Python文件。 You can only pass in variable bindings, not arguments. 您只能传递变量绑定,不能传递参数。

If you want to run a program from within Python, use subprocess.call. 如果要从Python内部运行程序,请使用subprocess.call。 Eg 例如

subprocess.call(['./abc.py', arg1, arg2])

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

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