I want to read from stdout of long-running command. There is a program, which sends me some output and I have to send some response.
The problem is that nothing is arriving to inputstream.
What am I doing, is exec'ing command, take InputStream from command and trying to read from there.
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new IgnoreHostKeyVerifier());
client.connect(getHostname(), getSshPort());
client.authPassword(getUsername(), getPassword());
Session sess = client.startSession();
Command cmd = sess.exec("/root/av_run/alarms");
InputStream is = cmd.getInputStream();
os = cmd.getOutputStream();
int piece;
while (true) {
if (is.available() > 0) {
piece = is.read();
} else {
Thread.sleep(500);
continue;
}
}
Here, is.available()
is always zero. If I read without that condition, reading is blocked forever.
How do I read stdout of a running program?