我试图写入输出流并读取简单的Autoit脚本的输入流。如果我不使用newLine()字符,我会得到预期的输出:一行发送到自动它,一行发送到java,然后重复。如果我添加newLine()字符,看起来每个周期都会有一个额外的行被发送到autoit。 这是为什么?Java,读写Autoit脚本的输入和输出流
的AutoIt:
Local $line
While (True)
$line = ConsoleRead()
ConsoleWrite($line & "to java" & @LF)
Sleep(25)
WEnd
的Java:
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
+1有趣的问题!我注意到,当我们进行更多的迭代时,我们总是将+1行设置为“autoit”,就像在输出中已经看到的一样。 – mrt