commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sayor Basu <>
Subject [NET] Windows Telnet Session restarts when sending commands
Date Thu, 10 May 2012 17:51:09 GMT

I am creating Telnet sessions to Windows as well as Linux servers to mount
a shared drive from my box, install a product using a single command line
and then check if all the services are running to verify by either tasklist
or ps and then looking for all the services from the returned response.
The Linux servers dont seem to have any problems, however on the Windows
servers I see that the session is restarted randomly - I get to see the
"Welcome to Microsoft Telnet Server." after writing a command to the
session. After this happens, even trying to send any more commands do not
help as I am not able to get the result of the command from the session.

I am using a sendCommand method which in turn does a write() and
readUntil() as in the code at the end.

So after the write, I get the Telnet welcome and when I am reading till the
system prompt e.g. ">" on Windows I do not get a response.
I have checked that the server does not reach the maximum no. of sessions
allowed or not reaching timeout and I have tried resending the command, but
that also does not produce any output.

Any suggestions on what I could try to get over this problem? Please let me
know if I can provide more information.


Code used for the writing a string to Telnet session command prompt and
reading from the prompt:

public void write(String value, Logger logger) throws Exception {
        try {
        } catch (Exception ex) {
            logger.println("Error while trying to write " + value +
".Details: " + Helper.getStackTraceAsString(ex));
            throw new Exception(ex);

public String readUntil(String pattern, Logger logger) throws Exception {
        StringBuffer sb = new StringBuffer();
        try {
            char ch = (char);
            int read =;
            while (read != -1) {
                ch = (char) read;
                if (sb.toString().endsWith(pattern)) {
                    return sb.toString();
                read =;
        } catch (Exception ex) {
            logger.println("Error while trying to read until " + pattern +
".Details: " + Helper.getStackTraceAsString(ex));
            throw new Exception(ex);
        throw new Exception("Telnet response doesn't end with '" + pattern
+ "' pattern. Response text : /n" + sb.toString());

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message