I debugged this by hacking some logging into Session.read(). The server 
was sending back results but it was not appearing on the input stream 
returned by ChannelExec.getInputStream().

The code was essentially doing this:

ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand("date");
channel.setInputStream(null);
channel.connect();
InputStream in = channel.getInputStream();

When I rearranged the order such that connect() was after 
getInputStream(), the results were available on the stream as expected.

Is it a contract of ChannelExec that connect() must be called after 
getInputStream()?

Thanks,

nat


On 5/21/2012 10:49 AM, Nat Wyatt wrote:
> Hi All,
>
> I have a question about how to debug a Jsch session.
>
> The application opens a single Jsch Session and creates multiple 
> ChannelExecs from it to run commands and process results. The commands 
> are run serially and synchronously from a single thread. The command 
> and result processing are patterned after 
> http://www.jcraft.com/jsch/examples/Exec.java. In a situation that I 
> can reproduce deterministically in my application but not in any test 
> framework, a command that should return results with a zero exit code 
> returns no results with a zero exit code.
>
> The command is a script that searches a system file, but I can get the 
> same results if the command is "echo foo" (in other words, when I 
> submit "echo foo" with a ChannelExec, isClosed() returns true, 
> getExitStatus() returns zero, but no data is ever available on the 
> input streams returned by getInputStream() or getErrStream()).
>
> I suspect that the problem is on the server side, not with Jsch, but I 
> can't figure out how to verify this. What I wish is there was a trace 
> flag that would show the commands and responses to/from the server. I 
> tried setting up a Logger as in 
> http://www.jcraft.com/jsch/examples/Logger.java. It gave me 
> information about the session setup, but no command/response traffic.
>
> Does anyone have a suggestion for how to debug this?
>
> Client is jsch-0.1.46 running on Android 2.3. Server is dd-wrt 
> v24-sp2. I think the SSH server is dropbear 0.52, and the shell is 
> busybox 1.13.4.
>
> Thanks,
>
> nat
>
>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to