jack liang
jack liang

Reputation: 1

Ganymed SSH2 JAVA, tips: Command not found

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?

Upvotes: 0

Views: 545

Answers (1)

YuMinghua
YuMinghua

Reputation: 1


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();
        }
    }
}

Upvotes: 0

Related Questions