У меня проблема в Java jsch. Я открыл канал оболочки, и у меня есть список команд, которые я хочу выполнить и прочитать из оболочки.
Но в этом списке команд есть одна команда, которую нужно прокрутить в оболочке, чтобы показано до конца.
Я изо всех сил пытаюсь реализовать этот автопрокрутка для этой команды.
В моем коде Что я сделал:
ChannelShell channelShell = (ChannelShell) session.openChannel("shell");
OutputStream inputstream_for_the_channel = channelShell.getOutputStream();
InputStream outputstream_from_the_channel = channelShell.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(outputstream_from_the_channel));
PrintStream commander = new PrintStream(inputstream_for_the_channel, true);
channelShell.connect();
if (!commands.get(0).equals("show system information | match \"System Name\"")) {
commands.add(0, "show system information | match \"System Name\"");
}
String readString = "";
String line;
int index = 0;
for (String cmd : commands) {
System.out.println(cmd);
commander.println(cmd);
try {
Thread.sleep(commandsSleep);
} catch (Exception ee) {
}
while ((line = reader.readLine()) != null)
{
if (cmd.equals("admin display-config")) {
commander.println("");
}
GuiApp.textAreaLog.append("\n"+ ++index + " : " + line);
System.out.println(index + " : " + line);
readString += (line+"\n");
}
}
if (routerType.equals("nokia")) {
commander.println("logout");
System.out.println("logout");
try {
Thread.sleep(commandsSleep);
} catch (Exception ee) {
}
} else if (routerType.equals("linux")){
commander.println("exit");
}
commander.close();
channelShell.disconnect();
try {
Thread.sleep(commandsSleep);
} catch (Exception ee) {
}
return readString;
В части:
while ((line = reader.readLine()) != null)
{
if (cmd.equals("admin display-config")) {
commander.println("");
}
GuiApp.textAreaLog.append("\n"+ ++index + " : " + line);
System.out.println(index + " : " + line);
readString += (line+"\n");
}
Это то место, где я пытался реализовать While l oop, чтобы читать считыватель до его нуля, и добавить к командующему printl с "", чтобы попытаться прокрутить эту команду c дальше вниз.