Ganymed SSH2 JAVA, tips: Command not found

545 Views Asked by At

Ganymed ,execCommand("java -version") Tips:bash: java: command not found But I use Shell tool, i can get the java version。 the ganymed can't get the local environmental variables? How can i do it?

1

There are 1 best solutions below

0
On

The reason for this problem is the lack of environmental variables. You can try the following code to solve.

public void execNoReturnRemoteCommand(String command, long timeout)
        throws Exception {
    Connection conn = getConnection();
    Session session = null;
    try {
        session = conn.openSession();
        session.requestPTY("bash");
        session.startShell();
        PrintWriter out = new PrintWriter(session.getStdin());
        out.println(command);
        out.println("exit");
        out.close();
        session.waitForCondition(ChannelCondition.CLOSED | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS, timeout*1000);
    } finally {
        if (session != null) {
            session.close();
        }
        if (conn != null) {
            conn.close();
        }
    }
}