1
SSH 프로토콜을 사용하는 원격 시스템에서 서비스를 실행하려고합니다. Ganymed SSH-2 Java 라이브러리 (버전 262) 사용하고 단일 명령을 실행하려면 잘 작동하지만 단일 세션 동안 여러 명령을 실행하는 동안 몇 가지 어려움을 직면했습니다.Session :: execCommand() 호출 후 IOException이 발생하는 이유는 무엇입니까?
왜 IOException이 발생하고 어떻게 해결할 수 있습니까?
, 아래의 발췌의 코드를 찾아주세요 :
private static void executeShellCommands(Connection connection, List<String> commandList) throws Exception {
Session session = connection.openSession();
InputStream stdout = new StreamGobbler(session.getStdout());
session.requestDumbPTY();
session.startShell();
for(String command : commandList) {
// The next line throws java.io.IOException
session.execCommand(command);
try (BufferedReader br = new BufferedReader(new InputStreamReader(stdout))) {
String line = br.readLine() + "\n";
StringBuilder shellOutput = new StringBuilder();
while (line != null) {
shellOutput.append(line);
line = br.readLine() + "\n";
}
}
}
session.close();
}
을 그리고 스택 트레이스는 다음과 같습니다
java.io.IOException: A remote execution has already started.
at ch.ethz.ssh2.Session.execCommand(Session.java:282)
at ch.ethz.ssh2.Session.execCommand(Session.java:260)
at com.myproject.test.ssh.util.SshOperations.executeShellCommands(SshOperations.java:124)
at com.myproject.test.ssh.util.SshOperations.runBatchProcessingService(SshOperations.java:147)
at com.myproject.test.ssh.step.definitions.DocumentBatchProcessingStepDefs.testFileIsCopiedToBpsViaSSH(DocumentBatchProcessingStepDefs.java:97)
at ✽.Given test file is copied to BPS via SSH (myrepo/src/test/resources/cucumber/Regression.feature:21)
미리 감사드립니다.