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

  • SEARCH
  • Home
  • 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 316593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:23:54+00:00 2026-05-12T08:23:54+00:00

I have a Java program that runs on Linux and telnets into a remote

  • 0

I have a Java program that runs on Linux and telnets into a remote server using org.apache.commons.net.telnet.TelnetClient and performs a few commands. The problem is that it hangs intermittently when it gets to an output display that asks the users to “press any key to continue…” The program hangs on this about 1 out of every 10 tims it runs and out of the 7 servers I run it on only 3 of the servers have problems. Also, when I run the same program on a windows box it works all the time.

I was wondering if anyone else has encountered a problem like this?

On a test server I can get it to hang every time to test with. I have tried to send in other commands that won’t cause it to hang but no luck. I have tried all the carrage return, line feed, adding a character and putting in a line feed. Nothing seems to make it client continue.

Forgot to mention that flushing the buffer what the first thing I thought of. I put the flush command anywhere I thought it might hlep.
I will also mention that when I run it and watch the output from the write line it does find the “press any key” and keeps going but hangs the terminal does not continue.

CODE WHERE I MAKE THE CALL:

        readUntil("X) Exit (no report)");
        write("C", false);
        out.flush();

        readUntil("continue....");

        // write this for all servers.
        write("", true);
        out.flush();

        readUntil("X) Exit");
        write("X", false);


/*
 * This method is used to read the command line until the pattern that was 
 * passed in is found.
 */
public String readUntil(String pattern) throws Exception {
    try {
        String tempString;
        char lastChar = pattern.charAt(pattern.length() - 1);
        StringBuffer sb = new StringBuffer();
        //boolean found = false;
        char ch = (char) in.read();
        while (true) 
        {
            // NOTE: Turn line below on to watch the program perform the telnet
            System.out.print(ch);

            sb.append(ch);
            tempString = sb.toString();
            if (ch == lastChar) {
                if (tempString.endsWith(pattern)) 
                {
                    // log to file
                    logFileWriter.write(tempString);
                    logFileWriter.flush();
                    return tempString;
                }
            }
            ch = (char) in.read();
        }
    }
    catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

/*
 * writes the String passed in to the command line.
 * boolean userWriteln: true - use the return key after the command, false - just type the 
 * command with NO enter key
 */
public void write(String value, boolean useWriteln) 
{

    System.out.println("WRITTING '" + value + "'");

    try {
        if (useWriteln)
        {
            out.println(value);
        }
        else
        {
            out.print(value);
        }
        out.flush();
        System.out.println(value);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

StackTrace: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at java.io.FilterInputStream.read(FilterInputStream.java:66)
at java.io.PushbackInputStream.read(PushbackInputStream.java:122)
at org.apache.commons.net.io.FromNetASCIIInputStream.__read(FromNetASCIIInputStream.java:77)
at org.apache.commons.net.io.FromNetASCIIInputStream.read(FromNetASCIIInputStream.java:175)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at org.apache.commons.net.telnet.TelnetInputStream.__read(TelnetInputStream.java:122)
at org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:564)
at java.lang.Thread.run(Thread.java:619)

WHERE IT HANGS:
english 1 6000 4462 26 % 13826 11056 20 %

Calls answered since Thu Jun  4, 2009  3:11 am: 41245

Press any key to continue….

  • 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-05-12T08:23:54+00:00Added an answer on May 12, 2026 at 8:23 am

    There might be several reasons:

    1. You’re not flushing your output (the input of the remote command), so the “any key” is never sent.

    2. The program tries to send you some data and you never read your input (the output of the remote command). Note that you must do this in a second thread since the I/O usually happens “at the same time” and one side will block if you don’t handle the other side timely enough.

    3. Maybe you experience a problem because the app turns the terminal into “RAW mode”. But flushing your output should fix that :/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 202k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Submitted a support call to microsoft and they responded: Entity… May 12, 2026 at 8:21 pm
  • Editorial Team
    Editorial Team added an answer You can't. NHibernate order by clause requires property names (aliases)… May 12, 2026 at 8:21 pm
  • Editorial Team
    Editorial Team added an answer Your "Service" class should implement IDisposable if it maintains references… May 12, 2026 at 8:21 pm

Related Questions

I am developing a scientific application used to perform physical simulations. The algorithms used
My experience with application servers is limited to some basic servlet coding, so I
I have a Java program that runs many small simulations. It runs a genetic
I have a java program that runs a bunch of queries against an sql

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.