这是我的简单AHK脚本:
MsgBox % "Hello world"
ExitApp, 7777
我通过以下代码从PHP运行这个AHK:
$result = exec('start path\ahk.exe', $output, $result_code);
现在我想从ahk.exe中获取一些数据。但是当我转储变量时:
var_dump($result, $output, $result_code);
结果是:
string(0) "" array(0) { } int(0)
所有的变量都是空的,那么,我如何在执行ahk.exe后得到一些有用的数据呢?
2条答案
按热度按时间6qfn3psc1#
您可以将结果存储在一个文本文件中,然后在PHP中读取该文本文件。
然后在PHP中调用exec函数,等待文件创建,然后使用
file_get_contents
获取结果。k10s72fa2#
编辑:看起来我得到了它在相反.我以为你想要你的PHP结果在AHK,但看起来你想要你的AHK结果在PHP.尽管如此,下面的概念应该对您有所帮助,因为AHK可以使用带星号的
FileAppend
命令写入StdOut(*
)的文件名,导致文本被发送到标准输出(标准输出)(但检查帮助-不是在当前控制台窗口,这与我的技术无关)。这是可以做到的,但我不确定你想实现什么。只是发送“Hello World”到控制台?PHP可以使用StdOut吗?
如果是这样,您可以使用
WScript.Shell
,然后在.Exec(ComSpec " /C cscript " command)
方法中传递命令,并返回exec.StdOut.ReadAll()
我有一个工作的例子如下,也许它会帮助你:
嗨,