com.jcraft.jsch.Channel.getExitStatus()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(488)

本文整理了Java中com.jcraft.jsch.Channel.getExitStatus()方法的一些代码示例,展示了Channel.getExitStatus()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channel.getExitStatus()方法的具体详情如下:
包路径:com.jcraft.jsch.Channel
类名称:Channel
方法名:getExitStatus

Channel.getExitStatus介绍

[英]retrieves the exit status of the remote command corresponding to this channel. The exit status is only available for certain types of channels, and only after the channel was closed (more exactly, just before the channel is closed).
[中]检索与此通道对应的远程命令的退出状态。退出状态仅适用于某些类型的通道,并且仅在通道关闭后(更确切地说,在通道关闭前)可用。

代码示例

代码示例来源:origin: alibaba/jstorm

if (channel.getExitStatus() != 0)
  throw new Exception("exitStatus:" + channel.getExitStatus());

代码示例来源:origin: alibaba/jstorm

System.out.println("exit-status: " + channel.getExitStatus());
break;

代码示例来源:origin: apache/kylin

if (in.available() > 0)
  continue;
exitCode = channel.getExitStatus();
logger.info("[" + username + "@" + hostname + "] Command exit-status: " + exitCode);

代码示例来源:origin: KylinOLAP/Kylin

if (in.available() > 0)
  continue;
exitCode = channel.getExitStatus();
System.out.println("[" + username + "@" + hostname + "] Command exit-status: " + exitCode);

代码示例来源:origin: net.sf.sshapi/sshapi-jsch

public int exitCode() throws IOException {
  return channel.getExitStatus();
}

代码示例来源:origin: Impetus/jumbune

private static void logJsch(Channel channel, InputStream in) 
  {
    try {
      byte[] tmp = new byte[1024];
      while (true) {
/*                while (in.available() > 0) {
          int i = in.read(tmp, 0, 1024);
          if (i < 0)
            break;
          LOGGER.debug(new String(tmp, 0, i));
        }
*/	            if (channel.isClosed()) {
          LOGGER.debug("exit-status: " + channel.getExitStatus());
          break;
        }
      }
    } catch (Exception ex) {
      LOGGER.error(ex);
    }
  }

代码示例来源:origin: org.rhq/rhq-enterprise-server

private String read(InputStream is, Channel channel) throws IOException {
  byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  final long endTime = System.currentTimeMillis() + TIMEOUT;
  while (System.currentTimeMillis() < endTime) {
    while (is.available() > 0) {
      int count = is.read(buffer, 0, DEFAULT_BUFFER_SIZE);
      if (count >= 0) {
        bos.write(buffer, 0, count);
      } else {
        break;
      }
    }
    if (channel.isClosed()) {
      if (log.isDebugEnabled()) {
        log.debug("SSH reading exit status=" + channel.getExitStatus());
      }
      break;
    }
    try {
      Thread.sleep(POLL_TIMEOUT);
    } catch (InterruptedException e) {
    }
  }
  return bos.toString();
}

代码示例来源:origin: org.apache.airavata/gsissh

public void onOutput(Channel channel) {
  try {
    InputStream inputStream = channel.getInputStream();
    byte[] tmp = new byte[1024];
    while (true) {
      while (inputStream.available() > 0) {
        int i = inputStream.read(tmp, 0, 1024);
        if (i < 0) break;
        System.out.print(new String(tmp, 0, i));
      }
      if (channel.isClosed()) {
        System.out.println("exit-status: " + channel.getExitStatus());
        break;
      }
      try {
        Thread.sleep(1000);
      } catch (Exception ignored) {
      }
    }
  } catch (IOException e) {
    logger.error(e.getMessage(), e);
  }
}

代码示例来源:origin: Impetus/jumbune

public static String getDaemonProcessId(Session session, String daemon) throws JSchException, IOException {
  String command = PID_COMMAND_PREFIX + daemon + PID_COMMAND_SUFFIX;
  session.connect();
  Channel channel = session.openChannel("shell");
  channel.connect();
  OutputStream os = channel.getOutputStream();
  InputStream is = channel.getInputStream();
  PrintStream ps = new PrintStream(os, true);
  String pid = "";
  try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
    ps.println(command);
    for (String line = br.readLine(); line != null; line = br.readLine()) {
      if (line.contains(daemon) && !line.contains("awk ")) {
        pid = line.split("\\s+")[1];
      }
    }
  }
  LOGGER.debug(" exit status - " + channel.getExitStatus() + ", daemon = " + daemon + ", PID = " + pid);
  if (channel != null && channel.isConnected()) {
    channel.disconnect();
  }
  if (session != null && session.isConnected()) {
    session.disconnect();
  }
  return pid;
}

代码示例来源:origin: Impetus/jumbune

public static String getDaemonProcessId(Session session, String daemon) throws JSchException, IOException {
  String command = PID_COMMAND_PREFIX + daemon + PID_COMMAND_SUFFIX;
  session.connect();
  Channel channel = session.openChannel("shell");
  channel.connect();
  OutputStream os = channel.getOutputStream();
  InputStream is = channel.getInputStream();
  PrintStream ps = new PrintStream(os, true);
  String pid = "";
  try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
    ps.println(command);
    for (String line = br.readLine(); line != null; line = br.readLine()) {
      if (line.contains(daemon) && !line.contains("awk ")) {
        pid = line.split("\\s+")[1];
      }
    }
  }
  LOGGER.debug(" exit status - " + channel.getExitStatus() + ", daemon = " + daemon + ", PID = " + pid);
  if (channel != null && channel.isConnected()) {
    channel.disconnect();
  }
  if (session != null && session.isConnected()) {
    session.disconnect();
  }
  return pid;
}

代码示例来源:origin: tote/ssh8

protected void execute(Channel channel, String pw) throws JSchException, IOException {
    channel.setInputStream(null);
    InputStream in=channel.getInputStream();
    OutputStream out=channel.getOutputStream();
    ((ChannelExec)channel).setErrStream(System.err);

    channel.connect();

    if(!pw.isEmpty()){
      out.write((pw+"\n").getBytes());
      out.flush();
    }
    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));
      }
      if(channel.isClosed()){
        System.out.println("exit-status: "+channel.getExitStatus());
        break;
      }
      try{Thread.sleep(1000);}catch(Exception ee){}
    }
    channel.disconnect();
  }
}

代码示例来源:origin: tote/ssh8

System.out.println("exit-status: "+channel.getExitStatus());
break;

代码示例来源:origin: hyperic/hq

System.out.println("exit-status: " + channel.getExitStatus());

代码示例来源:origin: org.cloudml/deployer

journal.log(Level.INFO, ">> exit-status: "+channel.getExitStatus());
break;

代码示例来源:origin: hadooparchitecturebook/fraud-detection-tutorial

System.out.println("exit-status: " + channel.getExitStatus());
break;

代码示例来源:origin: Microsoft/azure-tools-for-java

if(commandOutput.available()>0) continue;
if (getExitStatus) {
 result += "exit-status: " + channel.getExitStatus();
 if (withErr) {
  result += "\n With error:\n" + resultErr;

代码示例来源:origin: fr.ifremer/isis-fish

exitStatus = channel.getExitStatus();
if (log.isInfoEnabled()) {
  log.info("JSch channel exit-status: "

代码示例来源:origin: Impetus/jumbune

protected JschResponse getStringFromStream(Channel channel) throws IOException,
    JSchException {
  JschResponse jschResponse = new JschResponse();
  StringBuilder response = new StringBuilder();		
  InputStream in = channel.getInputStream();
  channel.connect();
  jschResponse.setChannelId(channel.getId());
  byte[] tmp = new byte[1024];
  while (true) {
    while (in.available() > 0) {
      int i = in.read(tmp, 0, 1024);
      if (i < 0)
        break;
      response.append(new String(tmp, 0, i));
    }
    if (channel.isClosed()) {
      if (in.available() > 0)
        continue;
      jschResponse.setChannelExitStatus(channel.getExitStatus());
      break;
    }
    try {
    } catch (Exception ee) {
      LOGGER.error("Exception occured while reading stream from Channel #Id["+jschResponse.getChannelId()+"]", ee);
    }
  }
  jschResponse.setResponse(response.toString());
  return jschResponse;
}

代码示例来源:origin: io.openscore.content/score-ssh

result.setExitCode(channel.getExitStatus());
  return result;
} catch (JSchException | UnsupportedEncodingException e) {

代码示例来源:origin: io.cloudslang.content/score-ssh

result.setExitCode(channel.getExitStatus());

相关文章