I am executing a command on the remote machine using JSch as below:
public String executeCommandNWaitForCompletion(String hostIp, String userName, String password, String command) throws Exception {
Session session = null;
ChannelExec channel = null;
InputStream in = null;
String response = "";
try {
session = getSession(hostIp, userName, password);
channel = (ChannelExec) session.openChannel("exec");
channel.setCommand(command);
channel.setInputStream(null);
channel.setErrStream(System.err);
in = channel.getInputStream();
channel.connect();
byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(tmp, 0, 1024);
if (i < 0) break;
response += new String(tmp, 0, i);
}
if (channel.isClosed()) {
if (in.available() > 0) continue;
log.debug("Exit-status: " + channel.getExitStatus());
break;
}
}
} finally {
if (in != null) in.close();
closeResources(session, channel);
}
return response;
}
In tomcat docker container this method is called from a spring mvc controller. Entire application works well but when this method is called, docker container logs are getting hanged and nothing gets displayed after that. But application runs as usual only logs gets hanged.
This method was running fine when we're running our app on Tomcat server directly but does not work in a docker container.
How to resolve this issue?