如何将变量从正在运行的 python 脚本发送到正在运行的 AHK 脚本?

问题描述 投票:0回答:1

我已经看到了一些关于使用 AHK 的参数运行 python 脚本的问题和答案,我想做的有点相反。

一种解决方案是在 python 中设置剪贴板的值,然后在 AHK 中读取它们。唯一的问题是它会扰乱剪贴板。

另一个解决方案是用 python 编写一个文本文件,然后在 AHK 中读取它,但我 如果计算机忙于其他进程,预计会出现高延迟 - 我需要一个需要 30 毫秒或更短时间的解决方案。

python autohotkey
1个回答
0
投票

这是可以做到的,但我不确定你想要完成什么。如果您使用 AHK 启动 python 脚本然后想要结果? Yjen 你可以使用标准输出,就像我之前展示的那样:

您使用

WScript.Shell
,然后在
.Exec(ComSpec " /C cscript " command)
方法中传递命令并返回
exec.StdOut.ReadAll()

我有一个工作示例(使用vbs而不是python)如下,也许对你有帮助:

;// The following runs a command (add.vbs) 
;// and retrieves its output via StdOut:

InputBox, x,,"Enter two numbers"
MsgBox % """" RunWaitOne("add.vbs " x) """" ;// result in quotes
ExitApp

RunWaitOne(command)
{
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec(ComSpec " /C cscript /nologo " command)
    return exec.StdOut.ReadAll()
}

/* This is the external "add.vbs" command:
a=3
b=4
if WScript.Arguments.Count > 0 Then
    a=cint(WScript.Arguments.Item(0))
    b=cint(WScript.Arguments.Item(1))
End If
Dim StdOut : Set StdOut = CreateObject("Scripting.FileSystemObject").GetStandardStream(1)
x=a+b
StdOut.Write x
*/

Hth,

© www.soinside.com 2019 - 2024. All rights reserved.