1

J2SSH ChannelInputStream read method is able to get the output from a command. However, if I try to execute a "tail -f file.txt > output.txt &" (bash) via J2SSH, read method gets locked. I think this is because there is no output to read in a "tail -f"...

Well, what I'm trying to do is to start a "tail -f" in background, read the bash output to ensure that the "tail" was started properly (no exit code error received from bash) and follow the flow of my java code (yes, tail -f will remain running in the OS). However, I'm getting locked in the (ChannelInputStream) read method, waiting for a output, probably from tail -f...

If I kill the tail -f process, the flow of the code back to normal. It means that (ChannelInputStream) read method does not working well with "tail -f".

Any suggestions? Any way to send something from bash to the read method to say to follow with the flow??

 while  ((bytesRead = stream.read(buffer,0,buffer.size()-1)) > 0){ ...

"stream is a ChannelInputStream type"

  • Maybe `tail -f file.txt > output.txt` buffers output so you won't see anything in output.txt until tail has about 4k or 8k to write. Could that be relevant? – Adrian Pronk Mar 16 '13 at 03:33

0 Answers0