1

First of all, thank you for your interest in my question. I need to pass the output value of the Linux command input to the Java Script front end. Since Linux runs on VMware, it connects using SSH on Windows Java. Is there a way to get the result of VMware's Linux command as a parameter in Java in Windows? This is the Java code I am currently using.

    SSHReturnMethod sshReturnMethod = new SSHReturnMethod();
    ArrayList totalmsg = null;
    String host = "test.rebex.net";
    String user = "demo";
    String password = "password";
    String command = "cleos wallet create --to-console";

    try {
        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        JSch jsch = new JSch();

        // Create a JSch session to connect to the server
        Session session = jsch.getSession("gpc", "192.168.3.128", 22);
        session.setPassword("password");
        session.setConfig(config);

        // Establish the connection
        session.connect();
        System.out.println("Connected...");

        ChannelExec channel = (ChannelExec) session.openChannel("exec");
        channel.setCommand(command);
        channel.setErrStream(System.err);


        InputStream in = channel.getInputStream();
        System.out.println(in);
        channel.connect();
        channel.connect();
        byte[] tmp = new byte[1024];
        while (true) {
            while (in.available() > 0) {
                int i = in.read(tmp, 0, 1024);
                if (i < 0) {
                    break;
                }
                System.out.print(new String(tmp, 0, i));
                System.out.print(new String(tmp, 0, i));
            }
            if (channel.isClosed()) {
                System.out.println("Exit Status: "
                        + channel.getExitStatus());
                break;
            }
            Thread.sleep(1000);
        }
        ArrayList valueOfReturn = sshReturnMethod.returnString(totalmsg); //value of return
        System.out.println(String.valueOf(valueOfReturn));
        channel.disconnect();
        session.disconnect();
        System.out.println("DONE!!!");
    } catch (Exception e) {
        e.printStackTrace();
    }

And this is the result value from java.

Connected... com.jcraft.jsch.Channel$MyPipedInputStream@51565ec2

Error 3120001: Wallet already exists Try to use different wallet name.

Exit Status: 1 return input is : null null DONE!!!

and I want

Error 3120001: Wallet already exists Try to use different wallet name.

create a method that returns this part.

Samuel Philipp
  • 10,631
  • 12
  • 36
  • 56
Dongkeydev
  • 11
  • 2

0 Answers0