简体   繁体   English

从AutoIt执行Python脚本

[英]Execute Python script from AutoIt

I have a Python (.py) file and need to execute it from AutoIt. 我有一个Python(.py)文件,需要从AutoIt中执行它。 How can I do this? 我怎样才能做到这一点?

Python scripts can be executed from command line. Python脚本可以从命令行执行。 For a script called myscript.py , you can run it (assuming Python is installed) by typing: 对于名为myscript.py的脚本,可以通过键入以下命令来运行它(假设已安装Python):

python myscript.py

If you want to run myscript.py without having to prefix it by python , then set the path to the Python binary (eg C:\\Python27\\Python.exe ) as Windows environment variable. 如果您想运行myscript.py而不用加python前缀,则将Windows变量(例如C:\\Python27\\Python.exe )的路径设置为Windows环境变量。 This enables AutoIt to execute the Python script as if it were an external program. 这使AutoIt可以像执行外部程序一样执行Python脚本。 Reference: ShellExecute() . 参考: ShellExecute()

ShellExecute("myscript.py")

Point to where myscript.py resides of course. 指向myscript.py当然驻留。 Use: 采用:

RunWait("C:\Python27\Python.exe myscript.py")

to avoid setting environment variables. 避免设置环境变量。

RunWait("C:\Python27\Python.exe filename.py")

此代码可以从autoit正常运行

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

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