I’m trying to write to the output stream and read the input stream of a simple Autoit script. If I do not use the newLine() character, I get the expected output: a line is sent to auto it, a line is sent to java, and that is repeated. If I add the newLine() character, it seems every cycle an extra line is sent to autoit. Why would this be?
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();
}
Output:
(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
Output I Expected:
(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
I’m no expert at this, not by any means, but consider these changes:
ConsoleRead()is that it is not blocking and I believe doesn’t recognize new lines. In other words, it’s does not behave in any way similar to Java’s Scanner.nextLine().StringSplit(...)function to split out the lines using @CRLF as the delimiter, and then pushing each String in the resulting array to the standard out usingConsoleWrite(...)StringInStr(...)function to test for a token that tells it to exit.For instance:
EchoCaller2.java
Echoer.au3