我正在尝试写入输出流并读取简单 Autoit 脚本的输入流。如果我不使用 newLine() 字符,我会得到预期的输出:发送一行来自动处理它,发送一行到 java,然后重复。如果我添加 newLine() 字符,似乎每个周期都会向 autoit 发送额外的一行。为什么会这样?
自动:
Local $line
While (True)
$line = ConsoleRead()
ConsoleWrite( $line & "to java" & @LF )
Sleep(25)
WEnd
爪哇:
p = Runtime.getRuntime().exec("Test");
in = new BufferedReader( new InputStreamReader(p.getInputStream()));
out = new BufferedWriter( new OutputStreamWriter(p.getOutputStream()));
int i=0;
out.write("(" + i++ + ") to autoit");
out.newLine();
out.flush();
while ((line = in.readLine()) != null) {
System.out.println(line);
out.write("(" + i + ") to autoit");
out.newLine();
out.flush();
if(i++ > 9)
p.destroy();
}
输出:
(0) to autoit
to java
(1) to autoit
(2) to autoit
to java
(3) to autoit
(4) to autoit
(5) to autoit
to java
(6) to autoit
(7) to autoit
(8) to autoit
(9) to autoit
to java
我预期的输出:
(0) to autoit
to java
(1) to autoit
to java
(2) to autoit
to java
(3) to autoit
to java
(4) to autoit
to java
(5) to autoit
to java
(6) to autoit
to java
(7) to autoit
to java
(8) to autoit
to java
(9) to autoit
to java