我已成功将SSH连接到节点,发送输入,并检索输出.输入一行后,该行将打印到控制台,然后是空白行,然后输出打印两次.我不希望输入在输入后打印到控制台,也不希望空行,也不要再次打印输出.以下是我的代码
public void runSession() {
try {
Channel channel = session.openChannel("shell");
channel.setInputStream(System.in, true);
channel.setOutputStream(System.out, true);
channel.connect(defaultChannelTimeout);
while (channel.getExitStatus() == -1) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.println(e);
}
}
channel.disconnect();
} catch(JSchException jschEx) {
System.out.println("JSch exception during I/O");
System.out.println(jschEx.getMessage());
}
}
这是控制台在运行时的样子
user:domain@node:/a/b/c> cd ..
cd ..
user:domain@node:/a/b>
user:domain@node:/a/b>
如您所见,存在以下问题:
>“cd ..”单独打印到控制台的一行
>“cd ..”后出现一个空行
>“user:domain @ node:/ a / b>”线打印两次.
有谁知道我如何删除这三个项目在控制台中显示?期望的输出是
user:domain@node:/a/b/c> cd..
user:domain@node:/a/b>