使用AutoIt将输入发送到命令行

时间:2014-07-26 03:46:08

标签: input command-line exe executable autoit

我是autoit的新手,我正在尝试自动输入.exe程序。这个可执行文件没有gui并且从命令窗口运行,所以我可以使用autoit通过命令窗口发送程序特定的输入吗?如果是这样,我怎么能这样做?

Local $engine= "C:\Users\Davis\Desktop\Chess engine\stockfish32bit.exe"
Local $PID = RunWait(@ComSpec & " /k " & $engine, "", "@SW_MAXIMIZE")
;Insert code that sends program "uci" as input

2 个答案:

答案 0 :(得分:2)

这个简单的例子展示了如何与之前运行的程序进行通信。

; Demonstrates the use of StdinWrite()
#include <Constants.au3>

Local $foo = Run("sort.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
; Write string to be sorted to child sort.exe's STDIN
StdinWrite($foo, "rat" & @CRLF & "cat" & @CRLF & "bat" & @CRLF)
; Calling with no 2nd arg closes stream
StdinWrite($foo)

; Read from child's STDOUT and show
Local $data
While True
    $data &= StdoutRead($foo)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "Debug", $data)

答案 1 :(得分:1)

Local $engine= "C:\Users\Davis\Desktop\Chess engine\stockfish32bit.exe"
Local $PID = RunWait(@ComSpec & " /k " & $engine, "", "@SW_MAXIMIZE")
$hCmd=WinGetHandle($engine)
ControlSend($hCmd, "", "", "uci" & @CR)