使用命令行参数执行外部程序



我想使用ShellExecuteWait()从 AutoIt 执行 Python 脚本。我的尝试:

$x = ShellExecuteWait("E:/Automation/Python/Scripts/ReadLog.py", '-f "file.log" -k "key" -e "errMsg" ')
MsgBox(0,"x=",String($x))
If @error Then
MsgBox(0,"Error=",String(@error))
EndIf

我可以在$x中看到一些进程 id,并且@error也设置为0(表示 AutoIt 执行了脚本(。但是我的 Python 脚本没有产生结果(它在独立执行时写入 txt 文件(。似乎问题在于传递命令行参数,例如:

ShellExecuteWait("E:/Automation/Python/Scripts/ReadLog.py", '-f "file.log" -k "key" -e "errMsg" ')

如何使用ShellExecuteWait()传递命令行参数?语法:

ShellExecuteWait ( "文件名" [, "参数" [, ">

workingdir" [,"verb" [, showflag]]]] (

参数:

文件名 :- 要运行的文件的名称(EXE、.txt、.lnk 等(。

参数 :- [可选] 程序的任何参数。空白 ("( 不使用任何值。

这错过了使用参数的示例。Python 脚本没有问题(它需要 3 个命令行参数、带有选项的字符串-f-k-e(。

相关:如何从autoit运行或执行python文件。

在 Windows 的系统环境/路径中检查 Python 二进制文件的路径(例如 Python.exe,无论您的 Python 程序/二进制文件位于何处(。

从AutoIt执行Python脚本 如果路径在那里,那么您的代码必须工作。在$x您将收到 Python 脚本的返回退出代码。

您也可以尝试:

RunWait('full_pathPython.exe ReadLog.py -f "file.log" -k "key" -e "errMsg"', 'full_path_of_working_directory')

AutoIt 不会执行外部程序/脚本,直到您传递工作目录(所有执行和运行命令的可选参数(。因此,将工作目录作为单独的参数传递,它将起作用:

RunWait('full_pathPython.exe ReadLog.py -f "file.log" -k "key" -e "errMsg"', 'full_path_of_working_directory')

最新更新