外部 CLI 程序的 AutoIt 脚本 - eac3to.exe
AutoIt Scripting for an External CLI Program - eac3to.exe
我正在尝试为名为 eac3to.exe 的 CLI 程序设计前端 GUI。我看到的问题是这个程序将它的所有输出发送到 cmd window。这给我带来了无穷无尽的麻烦,因为我需要将大量此类输出输入到 GUI window 中。这听起来很简单,但我开始怀疑我是否发现了 AutoIt 的局限性之一?
我可以将 运行() 函数与 windows 内部命令(例如 Dir)一起使用,然后使用 AutoIt StdoutRead()
函数将输出输出到一个变量中,但我只是无法从 eac3to.exe
等外部程序获得输出 - 无论我做什么,它似乎都不起作用!仅出于测试目的,我什至不需要将输出输出到 GUI window:只需使用 ConsoleWrite()
打印就足够了,因为这证明我能够将其读入变量。所以在这个阶段,这就是我需要做的 - 将我的外部 CLI 程序输出到 cmd window 的文本(通常大约 10 行)获取到一个变量中。一旦我能做到这一点,剩下的就容易多了。这是我一直在尝试的,但它从来没有奏效:
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", @SW_SHOW)
Global $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & @CRLF)
在 运行 之后,我从 consolWrite()
得到的所有脚本都是空行 - 而不是由于 运行 eac3to.exe
而输出的文本数据( 运行 没有任何参数的 eac3to 只是列出了与所有命令行选项相关的帮助文本屏幕),这就是我试图进入变量的内容,以便我可以稍后在程序中使用它。
Before I suggest a solution let me just tell you that Autoit has one
of the best help files out there. Use it.
你不见了$STDOUT_CHILD = Provide a handle to the child's STDOUT stream
。
此外,您不能只执行 运行 并立即调用 stdoutRead。您在什么时候给应用程序一些时间来做任何事情并实际将某些内容打印回控制台?
您需要使用 ProcessWaitClose
然后读取流,或者您应该循环读取流。最简单的检查是在 运行 和 READ 之间设置一个睡眠,看看会发生什么。
#include <AutoItConstants.au3>
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", @SW_SHOW, $STDOUT_CHILD)
; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)
; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
; If the proccess doesnt end when finished you need to put this inside of a loop.
Local $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & @CRLF)
我正在尝试为名为 eac3to.exe 的 CLI 程序设计前端 GUI。我看到的问题是这个程序将它的所有输出发送到 cmd window。这给我带来了无穷无尽的麻烦,因为我需要将大量此类输出输入到 GUI window 中。这听起来很简单,但我开始怀疑我是否发现了 AutoIt 的局限性之一?
我可以将 运行() 函数与 windows 内部命令(例如 Dir)一起使用,然后使用 AutoIt StdoutRead()
函数将输出输出到一个变量中,但我只是无法从 eac3to.exe
等外部程序获得输出 - 无论我做什么,它似乎都不起作用!仅出于测试目的,我什至不需要将输出输出到 GUI window:只需使用 ConsoleWrite()
打印就足够了,因为这证明我能够将其读入变量。所以在这个阶段,这就是我需要做的 - 将我的外部 CLI 程序输出到 cmd window 的文本(通常大约 10 行)获取到一个变量中。一旦我能做到这一点,剩下的就容易多了。这是我一直在尝试的,但它从来没有奏效:
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", @SW_SHOW)
Global $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & @CRLF)
在 运行 之后,我从 consolWrite()
得到的所有脚本都是空行 - 而不是由于 运行 eac3to.exe
而输出的文本数据( 运行 没有任何参数的 eac3to 只是列出了与所有命令行选项相关的帮助文本屏幕),这就是我试图进入变量的内容,以便我可以稍后在程序中使用它。
Before I suggest a solution let me just tell you that Autoit has one of the best help files out there. Use it.
你不见了$STDOUT_CHILD = Provide a handle to the child's STDOUT stream
。
此外,您不能只执行 运行 并立即调用 stdoutRead。您在什么时候给应用程序一些时间来做任何事情并实际将某些内容打印回控制台?
您需要使用 ProcessWaitClose
然后读取流,或者您应该循环读取流。最简单的检查是在 运行 和 READ 之间设置一个睡眠,看看会发生什么。
#include <AutoItConstants.au3>
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", @SW_SHOW, $STDOUT_CHILD)
; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)
; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
; If the proccess doesnt end when finished you need to put this inside of a loop.
Local $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & @CRLF)