使用jsch远程连接,执行cmd
public String execCmd(String command) throws Exception {
initChannelExec();
log.info("execCmd command - > {}", command);
channel.setInputStream(System.in);
channelExec.setCommand(command);
channel.connect();
StringBuilder sb = new StringBuilder(16);
try (InputStream in = channel.getInputStream();
InputStreamReader isr = new InputStreamReader(in, StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(isr)) {
String buffer;
while ((buffer = reader.readLine()) != null) {
log.info(buffer);
sb.append("\n").append(buffer);
}
log.info("execCmd result - > {}", sb);
return sb.toString();
}
}
执行远程python程序:hello_world.py
import time
print("hello world start")
time.sleep(10)
print("hello world end.")
输出不实时
log.info(buffer);这句打印hello world start 和hello world end是同时打印出来的,我想要先打印第一行,等10s再打印第二行,请问怎么实现