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

2024-10-02 14:30:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用^{}从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文件)。似乎问题在于传递命令行参数,例如:

^{pr2}$

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

ShellExecuteWait ( "filename" [, "parameters" [, "workingdir" [,"verb" [, showflag]]]] )

Parameters:

filename :- The name of the file to run (EXE, .txt, .lnk, etc).

parameters :- [optional] Any parameters for the program. Blank ("") uses none.

这会遗漏参数使用的范例。Python脚本没有问题(它需要3个命令行参数、带有选项-f-k-e的字符串)。在

相关:How to run or execute python file from autoit。在


Tags: thetorun命令行txt脚本参数string
2条回答

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

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

检查Python二进制文件的路径(例如。Python.exe,在窗口的系统环境/路径中。在

Execute Python script from AutoIt如果存在路径,则代码必须正常工作。在$x中,您将收到Python脚本的返回退出代码。在

您也可以尝试:

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

相关问题 更多 >