我正在尝试从 Sikuli (r930) 调用 Python (2.7) 脚本并使用脚本中的变量。下面是 Python 代码:
import sys
import re
import os
import time
from pywinauto import application
from SendKeys import SendKeys
from cStringIO import StringIO
app=application.Application()
app.connect_(path=r'C:\Program Files\myApp\myApp.exe')
backup = sys.stdout
sys.stdout = StringIO()
app.dlg.print_control_identifiers()
out = sys.stdout.getvalue()
sys.stdout.close() # close the stream
sys.stdout = backup # restore original stdout
regex = re.compile(r'(\d{8}\s*\-\s*\d{8})')
found = re.search(regex, out)
print found.group(0) #pass this variable to Sikuli
我正在捕获stdout
,因为这是Pywinauto 的 print_control_identifiers
方法返回的(不是字符串)。此外,我需要一个来自 GUI 应用程序的散列序列号,而我无法通过 Sikuli 获得,因此需要使用 Pywinauto。但是,当我尝试execfile()
从 Sikuli 拨打电话时,出现错误:
ImportError: no module named Pywinauto.
我阅读了文档,我知道 Sikuli (Jython) 可以包含 Python 模块和脚本。此外,我调用的外部 .py 文件在独立运行时运行成功。如果我错过了一步,有人可以告诉我吗?
我用来从 Sikuli 调用上面显示的 .py 文件的代码:
aScript = 'c:\\getHash_serial.py'
execfile(aScript)