java - How do I get rid of escape sequences when using SSHTools? -


i using sshtools / j2ssh connect server via ssh. works fine, problem is, output contains strange escape sequences / characters. read somewhere, these color codes , not encoding issue. question is: how rid of them? seems need sort of terminal emulation, interprets or strips off these codes.
here output of ls:

[0m[01;34msketchbook[0m  sketchbook.tar  sketchbook.tar.tar  [01;32msshsudo[0m  [01;34mtmp[0m  tmp.tar 

(note: there other commands need call, ls --color=never won’t job.)

i tried library jsch before, there can use ((channelshell)channel).setpty(false); rid of these characters, did not find similar sshtools.

okay, found out myself. download terminal components library.

then following work (based on this blogpost):

      iostreamconnector input = new iostreamconnector();       iostreamconnector error = new iostreamconnector();       input.setcloseinput(false);       error.setcloseoutput(false);       input.connect(system.in, session.getoutputstream());       error.connect(session.getstderrinputstream(), system.out);        inputstream in = session.getinputstream();       terminalemulation emulation = new terminalemulation("vt320");       emulation.setrecordprintableonly(true);       emulation.startrecording(system.out);       byte[] buf = new byte[1024];       int r;       while ((r = in.read(buf)) != -1) {           emulation.putbytes(buf, 0, r);       } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -