jsch
jsch copied to clipboard
Can you help me see a question?
trafficstars
Use exec to execute the command, execute it in large concurrency, and block on the stream for a period of time
logger.info(new StringBuilder(this.ip).append(",执行输出命令:").append(command).toString()); try (InputStream stdout = openChannel.getInputStream()) { openChannel.connect(); long startTime = System.currentTimeMillis(); byte[] tmp = new byte[1024]; while (true) { while (stdout.available() > 0) { int i = stdout.read(tmp, 0, 1024); if (i < 0) break; result.append(new String(tmp, 0, i, Charset.defaultCharset())); } if (openChannel.isClosed()) { if (stdout.available() > 0) continue; break; } // 超时 if (System.currentTimeMillis() - startTime > timeout) { throw new TimeOutException("sh命令执行超时:" + command); } }