Skip to content
Advertisement

Running command using “exec” channel with JSch does not return any output

I am trying to execute a command on a Linux server using SSH from Android with JSch.

As far as I know I am connecting to the server, but when I attempt to retrieve the results of the command I am getting nothing.

Connect to server:

JavaScript

Retrieve data:

JavaScript

What am I missing here?

Advertisement

Answer

You disconnect immediately after you start the command, before any output is returned.

You have to wait for the “exec” channel to close (it closes once the command finishes).

See the official JSch example for the “exec” channel.

JavaScript

Though to allow the command to reliably complete and to collect all output including the errors, see How to read JSch command output?

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement