Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9115793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:31:02+00:00 2026-06-17T04:31:02+00:00

I’m trying to write to the output stream and read the input stream of

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:31:03+00:00Added an answer on June 17, 2026 at 4:31 am

    I’m no expert at this, not by any means, but consider these changes:

    • A problem with Autoit’s 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().
    • It may in fact read in a whole bunch of lines all at once, and I’m not sure if this can be predicted.
    • Consider using AutoIt’s 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 using ConsoleWrite(...)
    • Consider having AutoIt use the StringInStr(...) function to test for a token that tells it to exit.
    • On the Java side, I think that you will need to read the text from standard in on a separate thread from that which you write so as not to be blocking.
    • I have used Scanner to parse the standard in, and like using PrintStream for ease in outputting to the standard out.

    For instance:

    EchoCaller2.java

    import java.io.BufferedOutputStream;
    import java.io.IOException;
    import java.io.PrintStream;
    import java.util.Scanner;
    
    public class EchoCaller2 {
       private static final String AUTO_IT_ECHOER = "Echoer.exe"; // AutoIt program
       private static Scanner scan = null;
       private static PrintStream out = null;
    
       public static void main(String[] args) throws IOException,
             InterruptedException {
          ProcessBuilder pb2 = new ProcessBuilder(AUTO_IT_ECHOER);
          pb2.redirectErrorStream();
          Process p = pb2.start();
          scan = new Scanner(p.getInputStream());
          out = new PrintStream(new BufferedOutputStream(p.getOutputStream()));
    
          new Thread(new Runnable() {
             public void run() {
                while (scan.hasNextLine()) {
                   System.out.println(scan.nextLine());
                }
                scan.close();
             }
          }).start();
    
          for (int i = 0; i < 10; i++) {
             out.println("(" + i + ") to autoit ");
             out.flush();
          }
    
          out.println("exit ");
          out.flush();
          out.close();
       }
    }
    

    Echoer.au3

    Local $line
    
    While (True)
    
        $line &= ConsoleRead()
    
        $strArray = StringSplit($line, @CRLF)
    
        If $strArray[0] > 0 Then
            For $r = 1 to $strArray[0]
                If StringLen($strArray[$r]) > 0 Then
                    ConsoleWrite($strArray[$r] & "to java" & @CRLF)
                EndIf
            Next
        EndIf
    
        If StringInStr($line, "exit") Then
            Exit
        EndIf
    
        $line = ""
    
        Sleep(25)
    
    WEnd
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am confused How to use looping for Json response Array in another Array.
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.