I'm trying to execute a script in background with nohup
and want to disconnect without reading output. Is it required to get and read input stream channel.getInputStream(); in.read(...)
in this case?
It is a long running script and I want get control back ASAP. If reading InputStream
is required, how to get control back ASAP without waiting for long.
String command = "nohup script.sh > /home/user1/output.txt 2>&1 &";
session.connect();
ChannelExec channel = (ChannelExec) session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
in.read(...)
channel.disconnect();
session.disconnect();