Search in sources :

Example 16 with ChannelExec

use of com.jcraft.jsch.ChannelExec in project ignite by apache.

the class StartNodeCallableImpl method exec.

/**
     * Gets the value of the specified environment variable.
     *
     * @param ses SSH session.
     * @param cmd environment variable name.
     * @return environment variable value.
     * @throws JSchException In case of SSH error.
     * @throws IOException If failed.
     */
private String exec(Session ses, String cmd) throws JSchException, IOException {
    ChannelExec ch = null;
    try {
        ch = (ChannelExec) ses.openChannel("exec");
        ch.setCommand(cmd);
        ch.connect();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(ch.getInputStream()))) {
            return reader.readLine();
        }
    } finally {
        if (ch != null && ch.isConnected())
            ch.disconnect();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ChannelExec(com.jcraft.jsch.ChannelExec)

Aggregations

ChannelExec (com.jcraft.jsch.ChannelExec)16 InputStream (java.io.InputStream)11 JSch (com.jcraft.jsch.JSch)7 Session (com.jcraft.jsch.Session)7 IOException (java.io.IOException)7 Channel (com.jcraft.jsch.Channel)6 JSchException (com.jcraft.jsch.JSchException)6 BufferedReader (java.io.BufferedReader)6 InputStreamReader (java.io.InputStreamReader)6 FileInputStream (java.io.FileInputStream)5 OutputStream (java.io.OutputStream)5 UserInfo (com.jcraft.jsch.UserInfo)3 File (java.io.File)3 SftpException (com.jcraft.jsch.SftpException)2 FileOutputStream (java.io.FileOutputStream)2 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)2 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)1 UserInfoPrompted (edu.umass.cs.aws.networktools.UserInfoPrompted)1 HeadlessException (java.awt.HeadlessException)1