[AHK]python调用ahk,并读取ahk的执行结果
2017-01-16 21:27
1291 查看
转自: http://blog.csdn.net/tumin999/article/details/51206493
2016-04-21 10:53
目前使用ahk脚本(已编译成独立exe)来执行一个动作,而Python主程序负责调用这些不同的ahk程序。
以前是通过系统粘贴板来交互数据,即ahk程序启动后清除粘贴板,在结束时将执行情况已文字方式拷贝到粘贴板,python程序在等待ahk进程结束后再从粘贴板中读取执行结果。很显然这种方式有些弊端,比如不能同时执行多个ahk程序,还要避免人在电脑上进行ctrl-c ctrl-v的操作等。
研究了python的subprocess库,发现可以利用stdin stdout等来在进程间传递数据:
[python]
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.
To also capture standard error in the result, use
stderr=subprocess.STDOUT
在AHK脚本中可以这样写回数据:
[ahk]
stdout := FileOpen("*", "w")
stdout.write(result)
stdout.close()
一个实际的例子:
[python]
ahk_res = subprocess.check_output([r"my_ahk.exe", "param1", "param2"])
print(ahk_res.decode("gbk"))
2016-04-21 10:53
目前使用ahk脚本(已编译成独立exe)来执行一个动作,而Python主程序负责调用这些不同的ahk程序。
以前是通过系统粘贴板来交互数据,即ahk程序启动后清除粘贴板,在结束时将执行情况已文字方式拷贝到粘贴板,python程序在等待ahk进程结束后再从粘贴板中读取执行结果。很显然这种方式有些弊端,比如不能同时执行多个ahk程序,还要避免人在电脑上进行ctrl-c ctrl-v的操作等。
研究了python的subprocess库,发现可以利用stdin stdout等来在进程间传递数据:
[python]
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.
To also capture standard error in the result, use
stderr=subprocess.STDOUT
在AHK脚本中可以这样写回数据:
[ahk]
stdout := FileOpen("*", "w")
stdout.write(result)
stdout.close()
一个实际的例子:
[python]
ahk_res = subprocess.check_output([r"my_ahk.exe", "param1", "param2"])
print(ahk_res.decode("gbk"))
相关文章推荐
- python调用ahk,并读取ahk的执行结果。
- Python读取UTF-8编码文件并使用命令行执行时输出结果的问题
- C#如何调用Python执行脚本,并将执行结果显示值显示至C#界面
- python读取 .txt 文本内容以及将程序执行结果写入txt文件
- 从 stdin 读取输入的C程序示例 && python脚本调用可执行文件
- window下java调用python脚本并读取Python运行结果
- C#如何调用Python执行脚本,并将执行结果显示值显示至C#界面
- 解决Ajax在兼容模式下后台调用执行两次结果不变的问题(已解决)!
- 自动旁注并多进程调用wwwscan扫描旁注结果的python脚本。
- 关于Python中并发调用管道执行外部程序的问题解决
- 用python script将QC Test plan 执行结果导入excel
- python调用其它脚本:pig,python,shell等等 (如何获取pig脚本执行的返回值)
- java JDBC最基本的操作读取、调用存储过程、执行批处理、事务等
- asp:ScriptManager 调用WebService. (ViewManager呈现一个Ascx的执行结果)
- python调用os.system执行系统命令,中文输出显示乱码
- python 调用mysql存储过程返回结果集
- 执行shell命令并读取执行结果——popen()的用法
- python调用linux shell脚本,并返回结果一例
- java JDBC最基本的操作读取、调用存储过程、执行批处理、事务等
- Python 调用CAPICOM 读取 USB-KEY数字证书