jQuery terminal - Reading shell response in Java as string shows weird characters in jQuery terminal

Displee :

I'm currently using a piped input/output stream principe to read from and write to a shell channel using JSCH.

Problem: I'm getting weird characters in my jQuery terminal when I transport the response of the shell to jQuery terminal.

Weird characters (jQuery terminal): enter image description here

I tried reading the piped input stream in different ways to solve the problem:

Try 1:

private synchronized String readResponse() throws IOException {
    byte[] array = new byte[pin.available()];
    pin.read(array);
    return new String(array, Charset.forName("UTF-8"));
}

Try 2:

private synchronized String readResponse() throws IOException {
        final StringBuilder s = new StringBuilder();
        while(pin.available() > 0) {
            s.append((char) pin.read());
        }
        return s.toString();
    }

Sadly this problem still persist. Can anyone help me?

Update: I just found out that, when I print the same string in my Java output console, it works.

Java's System.out: enter image description here

Update 2: I've imported the unix_formatting.js file and it's almost fixed. The thing with this file is that it has limited support for unix escape codes. Link to js: https://unpkg.com/[email protected]/js/unix_formatting.js

Currently looks like this: enter image description here

How can I fix this problem in jQuery terminal?

jcubic :

The problem you're having is that by default jQuery Terminal don't support ANSI escape codes but you can enable basic support by including unix_formatting.js file, the file is created using UMD so you can import it and have it in Webpack or Rollup bundle or include it using script tag:

Simplest is using unpkg.com:

<script src="https://unpkg.com/jquery.terminal/js/unix_formatting.js"></script>

you can also use same CDN as for main files (jsDeliver or cdnJS)

I think that cdn.rawgit.com will work until October 2019 so it's better to not use that one.

But, the one thing that jQuery Terminal can't do so is that you will never be able to display interactive shell command in Terminal in browser. The library was created for writing your own commands in JavaScript with basic support for shell command in unix_formatting file.

If you want to have full unix terminal in browser the better choice will be xterm.js which is real tty. If you can run the server, which you probably can if you're running java then xterm.js will be much better. You can even run vi or emacs -nw with it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=133086&siteId=1