Re: [JSch-users] JSCH .53 return empty strings executing commands on ubuntu
Status: Alpha
Brought to you by:
ymnk
From: Offer B. <off...@gm...> - 2016-05-18 10:45:35
|
ok... tried it as it is in the example and i still get the same result... every once in a while i get nothing back. that is the channel is closed and there is no available stuff to read. On Wed, May 18, 2016 at 1:30 PM, Offer Baruch <off...@gm...> wrote: > but read should block until you get data or you reach EOF... it shouldn't > return -1 if there might be anymore data... > as -1 (End Of File) was returned that means that no more data is available. > > anyway i will give it a try and report back. > > On Wed, May 18, 2016 at 12:48 PM, Tobia Conforto < > tob...@gr...> wrote: > >> Then I believe it's a race condition. >> >> You are looping until connIn.read() returns -1, but that only means that >> *for now* there is no more data to read. It doesn't mean that the remote >> command is done. So if the remote server takes a few millisecond more to >> run the command, your Java program will get a -1 from read() and exit the >> loop, instead of waiting for any more data. >> >> I suggest you study the examples provided with JSch, starting from the >> one about Exec[1], where you will see the only condition that can ever >> leave the main while(true) is basically: channel.isClosed() && ! >> in.available()>0 >> >> Tobia >> >> [1] http://www.jcraft.com/jsch/examples/Exec.java.html >> >> On 18 May 2016, at 11:38, Offer Baruch <off...@gm...> wrote: >> > basically i get into a read loop: >> > while (!endOfIn) { >> > i = connIn.read(tmp, 0, tempBufLen); >> > if (i < 0) { >> > endOfIn = true; >> > break; >> > } >> > ... >> > } >> > although this is surrounded by try and catch there is no exception >> raised... >> > i simply returns -1. >> > the command is in fact get run on the host... i just loose the output >> of the command. >> >> > |