The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Using BufferedReader to get the unix prompt back from RLogin process

Posted by Kim Vu on November 21, 2001 at 12:03 PM

Hi all,

Im currently having problems running the Runtime.getRuntime().exec("/usr/bin/rlogin") in order for me to get back my command line prompt. So if I log into a terminal called teletubby, then I would be expecting a prompt

" teletubby% "

after login. This seems to work using the DataInputStream class, but not when using BufferedReader class. Anyone have any ideas?

Here is my code:
import java.io.* ;

public class RLogin
{

public static void main(String args[])
{
// Start child, assuming it reads input from stdin
// and writes output to stdout.
Process p = null ;
try
{
String[] s = new String[4] ;
s[0] = "/usr/bin/rlogin" ;
s[1] = "-l" ;
s[2] = "x" ; //Username - x
s[3] = "y" ; //remote machine - y

p = Runtime.getRuntime().exec(s) ;
System.out.println("Child running") ;

//DataInputStream dIn = new DataInputStream(p.getInputStream()) ;
BufferedInputStream buffer = new BufferedInputStream(p.getInputStream());
BufferedReader cmdResult = new BufferedReader(new InputStreamReader(buffer));

try{
while(true)
{
String s = cmdResult.readLine();
if(s == null)
break;
System.out.println(s);
System.out.flush();
}
}
/*
try
{
int c ;
while ( (c = dIn.read()) != -1)
System.out.print((char)c) ;

}
*/
catch (IOException e)
{
System.out.println("\\nRead failed" ) ;
}

try
{
p.waitFor() ;
}
catch (InterruptedException e)
{
System.out.println("wait was interrupted") ;
}

}
catch (IOException e)
{
System.out.println("Exec failed" ) ;
}

p.destroy() ;
}
}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us