0
以前曾询问过这个问题,但我认为这些例子有点混乱。 这里是我的情况:使用AutoIt从控制台捕获输出
脚本:Python的 位置:在Windows机器上 “C:\用户\ Somedomain \桌面\ TEMP \ test.py”
Test.py看起来是这样的:
def Fun1(t):
import time
print t.capitalize()
time.sleep(5)
return t.capitalize()
if __name__ == "__main__":
Fun1('arindam')
我可以从CMD提示符(按Ctrl + R)运行它,然后将其粘贴: 蟒C:\用户\ inchowar \桌面\ TEMP \ test.py
AutoIt脚本看起来像:
#include <Constants.au3>
$temp = MyFun1()
MsgBox(64, "Result", $temp)
Func MyFun1()
Local $pid = Run('python C:\Users\inchowar\Desktop\Temp\test.py')
if ProcessExists($pid) Then
MsgBox(64, 'Result', 'Its Works..Till here')
$var = StdoutRead($pid)
MsgBox(64, 'Result', $var)
EndIf
ProcessClose($pid)
EndFunc
什么,我想在这里做的事:
我想在MSGBOX输出 “阿瑞丹姆” 显示是$ var。
通过上面的脚本,python脚本运行,在shell上显示输出,然后主MsgBox显示空白。第一个msgbox会在弹出成功时显示出来,证明pid确实存在。