I'm attempting to execute four commands on a remote server in Java. Since the commands involve exports, I've chained them together into one command:
rm -f nohup.out && export <a few similar commands> && nohup #here I execute a
startup script#>nohup.out >nohup.out 2>nohup.err </dev/null &
I then want to wait a bit (around 30 seconds) and parse an IP address from nohup.out. The problem I'm having is that the program hangs and doesn't seem to break the connection - debug code indicates it breaks somewhere in the code block below, since it does in fact execute the command server-side successfully
How do I successfully shut the connection?
The sending code, which uses JSch and comes from an upvoted solution on this site is as follows. There is a debug line after this that is never reached.
((ChannelExec)channel).setCommand(command);
InputStream commandOutput = channel.getInputStream();
channel.connect();
int readByte = commandOutput.read();
while(readByte != 0xffffffff)
//while (true)
{
outputBuffer.append((char)readByte);
readByte = commandOutput.read();
}