Java capturing telnet output in file -
i trying telnet server, run command , put output of command in file. can command in file not result of command. cannot see output on console either, assumed run not sure. have idea?
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 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); }
i not sure telneclient, if commons net class, missing part reads data exchanged during telnet session. please run this example , see how works, once you'll able cut needs.
Comments
Post a Comment