python调用ahk,并读取ahk的执行结果。
来源:互联网 发布:linux 美国纽约时区 编辑:程序博客网 时间:2024/05/20 22:02
目前使用ahk脚本(已编译成独立exe)来执行一个动作,而python主程序负责调用这些不同的ahk程序。
以前是通过系统粘贴板来交互数据,即ahk程序启动后清除粘贴板,在结束时将执行情况已文字方式拷贝到粘贴板,python程序在等待ahk进程结束后再从粘贴板中读取执行结果。很显然这种方式有些弊端,比如不能同时执行多个ahk程序,还要避免人在电脑上进行ctrl-c ctrl-v的操作等。
研究了python的subprocess库,发现可以利用stdin stdout等来在进程间传递数据:
subprocess.check_output(args, *, input=None, stdin=None, stderr=None, shell=False, universal_newlines=False, timeout=None) Run command with arguments and return its output. By default, this function will return the data as encoded bytes. The actual encoding of the output data may depend on the command being invoked, so the decoding to text will often need to be handled at the application level. <p> To also capture standard error in the result, use <tt class="docutils literal"><span class="pre">stderr=subprocess.STDOUT</span></tt>:</p>在AHK脚本中可以这样写回数据:
stdout := FileOpen("*", "w") stdout.write(result) stdout.close()
一个实际的例子:
ahk_res = subprocess.check_output([r"my_ahk.exe", "param1", "param2"]) print(ahk_res.decode("gbk"))
0 0
- [AHK]python调用ahk,并读取ahk的执行结果
- python调用ahk,并读取ahk的执行结果。
- [AHK]用AHK执行JavaScript
- AHK
- [AHK]用ahk执行VBScript脚本
- [AHK]读取硬件信息
- [WIN32][AHK]sapi.spvoice的调用
- [AHK]StrokesPlus调用AutoHotkey脚本的实践
- PyAutoGUI-python版的autoit/AHK
- PyAutoGUI-python版的autoit/AHK
- [AHK]爬虫基础 解析IP138网站返回的结果
- [ahk]读取excel文件实例
- AHK~与$的含义
- AHK的运算符
- AHK的常用函数
- AHK的按键
- [AHK]随叫随到的记事本
- [FUNC]模仿python的range实现ahk的for循环
- DataFrame registerTempTable(注册临时表)后Table Not Found问题的解决
- QuartZ Cron表达式
- [IOS/UINavigation]设置 UINavigationBar的返回按键图片
- c++实验4—利用循环求和
- IMSI与IMEI 概念
- python调用ahk,并读取ahk的执行结果。
- Android调用手机中的应用市场,实现评分功能
- Spring装配集合的四个方法及实现
- 【bzoj2310】ParkII 插头dp
- Android对Bitmap处理的工具类
- xcode7.3中使用SpriteKit开发游戏时如何使用atlasc贴图集(使用TexturePacker生成)
- android 系统提示对话框(AlertDialog)的使用
- 粒子滤波 演示与opencv代码
- 短信验证码