telnet Abfrage

azenth

Mitglied
Hi Leute,

ich habe ein Problem. Ich würde gerne aus meinem Java Programm heraus eine telnet - Abfrage machen und das was zurück kommt in einer String Variable speichern um es weiter verarbeiten zu können.

Es soll quasi einfach nur "telnet <server|ip> <port>" ausgeführt werden.

Leider habe ich absolut keinen Ansatzpunkt wie ich das Problem lösen könnte. Hat jemand einen Tipp für mich?



Gruß
Azenth
 
Zuletzt bearbeitet:
Moin,

Du kannst andere Programme über "Runtime" aufrufen!

Kurzes Beispiel:
Java:
final String strURL =  "www.google.de";
String sCMD = "C:\\Programme\\Internet Explorer\\iexplore.exe \"" + strURL.trim() + "\"";
try
{
    procIExplorerRunning = Runtime.getRuntime().exec( sCMD );
}
catch( IOException e )
{
    e.printStackTrace();
}

Gruß
Klaus
 
Hallo Klaus,

mein Code sieht wie folgt aus

Code:
String cmd = "telnet " + ip + " 6556";
Process p = Runtime.getRuntime().exec(cmd);
			   
BufferedReader lsOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = lsOut.readLine();
lsOut.close();

Ich hätte erwartet, dass dies gehen sollte, jedoch bekomme ich als Resultat null zurück. In der CMD bekomme ich aber massig Werte zurück.

Ist etwas falsch an meinem Code?

Gruß
Azenth
 
Moin,

dies steht in der API:
getInputStream

public abstract InputStream getInputStream()

Returns the input stream connected to the normal output of the subprocess. The stream obtains data piped from the standard output of the process represented by this Process object.

If the standard output of the subprocess has been redirected using ProcessBuilder.redirectOutput then this method will return a null input stream.

Otherwise, if the standard error of the subprocess has been redirected using ProcessBuilder.redirectErrorStream then the input stream returned by this method will receive the merged standard output and the standard error of the subprocess.

Implementation note: It is a good idea for the returned input stream to be buffered.

Returns:
the input stream connected to the normal output of the subprocess

Vielleicht hilft Dir die markierte Zeile weiter !

Gruß
Klaus
 

Neue Themen


Zurück
Oben