Suponiendo que "theTC" es un org.apache.commons.net.telnet.TelnetClient; con una conexión abierta, yo lo hacía así:
Código:
/**
* @param command
* @param timeout
* @return @throws
* IOException
* @throws InterruptedException
*/
public List executeCommand(
String command, long timeout)
throws IOException, InterruptedException
{
List answerLines = new ArrayList();
if (started)
{
OutputStream theOS = theTC.getOutputStream();
theOS.write((command + "\n").getBytes());
theOS.flush();
Thread.sleep(timeout);
ByteArrayInputStream theBAIS = new ByteArrayInputStream(theTAR
.getResult());
InputStreamReader theISR = new InputStreamReader(theBAIS);
BufferedReader theBR = new BufferedReader(theISR);
String theLine = null;
while ((theLine = theBR.readLine()) != null)
{
answerLines.add(theLine);
}
}
return answerLines;
}
Y el método ejecutado en un Thread distinto del programa principal, para que no se quedara colgado esperando.
S!