Java capturing telnet output in file

shababjo

New Member
I am trying to telnet to a server, run a command and put the output of that command in a file.I can get the command in the file but not the result of this command.I cannot see my output on my console either, so I assumed it run but I am not sure. Does anybody have any idea?\[code\]public final static void main(String[] args) throws IOException, InterruptedException{ FileOutputStream fout = null; try { fout = new FileOutputStream ("spyfile.log"); } catch (IOException e) { System.err.println( "Exception while opening the spy file: " + e.getMessage()); } TelnetClient telnet; telnet = new TelnetClient(); try { telnet.connect("myserver", 23); } catch (IOException e) { e.printStackTrace(); System.exit(1); } telnet.registerSpyStream(fout); PrintStream out = new PrintStream( telnet.getOutputStream() ); out.println( "mycommand" ); try { telnet.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } fout.close(); System.exit(0); }\[/code\]
 
Top