package net.schmizz.sshj.examples;

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/** This examples demonstrates how a remote command can be executed. */
public class Exec {

    public static void main(String... args)
            throws IOException {
        final SSHClient ssh = new SSHClient();
        ssh.loadKnownHosts();

        ssh.connect("localhost");
        try {
            ssh.authPublickey(System.getProperty("user.name"));
            final Session session = ssh.startSession();
            try {
                final Command cmd = session.exec("ping -c 1 google.com");
                System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
                cmd.join(5, TimeUnit.SECONDS);
                System.out.println("\n** exit status: " + cmd.getExitStatus());
            } finally {
                session.close();
            }
        } finally {
            ssh.disconnect();
        }
    }

}

@@ -718,30 +718,8 @@
 ();%0A
-            try %7B%0A    
     
@@ -780,28 +780,24 @@
 ogle.com%22);%0A
-    
             
@@ -880,20 +880,16 @@
         
-    
 cmd.join
@@ -911,20 +911,16 @@
 CONDS);%0A
-    
         
@@ -991,28 +991,24 @@
 ));%0A        
-    
 %7D finally %7B%0A
@@ -999,32 +999,50 @@
     %7D finally %7B%0A
+            try %7B%0A
                 
@@ -1071,36 +1071,100 @@
        %7D
-%0A        %7D finally %7B
+ catch (IOException e) %7B%0A                // Do Nothing   %0A            %7D%0A            
 %0A       

Remove unnecessary nested try/finally (#417)