You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Poornima BS <po...@gmail.com> on 2017/01/20 13:32:45 UTC

ExecChannel getExitStatus

Hi,

How can i make sure if channel is closed after complete execution.

And make use of getExitStatus method to ensure if script execution was
successful.

Please find the below snippet

```

ExecChannel channel = ssh.execChannel(serviceScript);

bufferedReader = new BufferedReader(new
InputStreamReader(channel.getOutput()));
String msg=null;
LOGGER.info(String.format("Initiated sending logs to subscribed user %s",
prinicipal.getName()));
RealTimeExecutionLogs realTimeExecutionLogs = new RealTimeExecutionLogs();;
while((msg=bufferedReader.readLine())!=null){
LOGGER.info(msg);
realTimeExecutionLogs.setContent(msg);
template.convertAndSendToUser(prinicipal.getName(),
"/queue/executeService", realTimeExecutionLogs);
}

channel.getExitStatus().get() -------- the exit status of the command if it
was received, or {@code null} if this information
    *         was not received.

```


Thanks & regards,
Poornima.BS

Re: ExecChannel getExitStatus

Posted by Ignasi Barrera <na...@apache.org>.
HI,

The getExitStatus().get() call should block until the command
completes. When it's done, it is just a matter of calling
"channel.close()" and that will close all open streams and release the
resources associated to this connection.


I.

On 20 January 2017 at 14:32, Poornima BS <po...@gmail.com> wrote:
> Hi,
>
> How can i make sure if channel is closed after complete execution.
>
> And make use of getExitStatus method to ensure if script execution was
> successful.
>
> Please find the below snippet
>
> ```
>
> ExecChannel channel = ssh.execChannel(serviceScript);
>
> bufferedReader = new BufferedReader(new
> InputStreamReader(channel.getOutput()));
> String msg=null;
> LOGGER.info(String.format("Initiated sending logs to subscribed user %s",
> prinicipal.getName()));
> RealTimeExecutionLogs realTimeExecutionLogs = new RealTimeExecutionLogs();;
> while((msg=bufferedReader.readLine())!=null){
> LOGGER.info(msg);
> realTimeExecutionLogs.setContent(msg);
> template.convertAndSendToUser(prinicipal.getName(),
> "/queue/executeService", realTimeExecutionLogs);
> }
>
> channel.getExitStatus().get() -------- the exit status of the command if it
> was received, or {@code null} if this information
>     *         was not received.
>
> ```
>
>
> Thanks & regards,
> Poornima.BS