Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

telnet in Win2000/XP using java runtime.exec ??  RSS feed

 
Prithvi Raj
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to start the telnet session from java . the following code works fine in 98/ nt 4.0 but it does not work in win2k/XP . if returns an exitvalue of -1 thats all. can any one tell me why . is it because the telnet program in these environments seem to work differently because they do not open the window as in 98 or NT 4.0 . any work arounds
Process p = Runtime.getRuntime().exec("telnet");
BufferedReader br = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedWriter bw = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));
bw.write("1");
bw.flush();
String line;
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
br.close();
bw.close();
System.out.println(p.exitValue());
 
Christopher Dixon
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

You'll have to check the OS name using System.getProperty("os.name") because the command strings are different for 95/98/NT/2000.
The question I would ask is whether you truly need to use Runtime.exec()? There are quite a few Java Telnet implementations that are available and don't require you to compromise platform independence.
I've used the ORO packages. They haven't been updated in a while, but then again neither have most of the protocols that they represent.
Check out the API:com.oroinc.net
Chris
 
Prithvi Raj
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Christopher
Thanx a lot for u r input. it is working great. i did not want to use that api was because the telnet session data acts as interface to another third party software.
thanx again
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!