SSHJ Different results on Windows and Linux
===

I have a class that I wrote that uses the SSHJ libraries to connect to server using ssh and run a specific command.  When I tested in Windows XP running under Java version 1.6.0_33 in the NetBean development environment it works fine.  When I run it on my Linux RedHat box under Java version 1.6.0_20 it hangs.  I have traced it the fact that the input stream is not being passed to the java class that is calling my SSHExec class or something along that line.  When I read the input stream in the SSHExec class the command completes, but the calling program does not get the output of the command.  

Below is the code for the SSHExec class and a test procedure to show what is happening.

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package backup;
    
    import java.io.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import net.schmizz.sshj.SSHClient;
    import net.schmizz.sshj.connection.channel.direct.Session;
    
    /**
     *
     * @author flb
     */
    public class SSHExec extends SSHClient{
        private static Session session = null;
        private static SSHClient ssh = null;
        
        public String host = "";
        public String userId = "";
        public String keyFile = "";   
        public InputStream inputStream;
        public OutputStream outputStream;
        public InputStream errorStream;
        public Integer exitStatus;
           
        public void exec (String host, String userId, String keyFile, String cmd){
            this.host = host;
            this.userId = userId;
            this.keyFile = keyFile;
            
            try{
                this.exec(cmd);
            } catch (Throwable t){
                Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, t);
            }
        }
        
        public void exec (String cmdString) {        
            this.exitStatus = null;
            
            try { 
                
                if (this.host.isEmpty()) {
                    throw new Error("Host value not set.");
                }
                
                if (this.userId.isEmpty()) {
                    throw new Error("User id is not set.");
                }
                
                if (this.keyFile.isEmpty()) {
                    throw new Error("Password is not set.");
                }
                
                if (cmdString.isEmpty()) {
                    throw new Error("No command to execute.");
                }
                
                System.out.println("create ssh client");
                ssh = new SSHClient();
                System.out.println("ssh client created");
                ssh.loadKnownHosts();
                System.out.println("ssh connect to " + this.host);
                ssh.connect(this.host);
                System.out.println("authencate public key | " + this.userId + " | " + this.keyFile);
                ssh.authPublickey(this.userId, this.keyFile);
                
                System.out.println("start the session");
                session = ssh.startSession();
                System.out.println("session started");
                
                System.out.println("execute the command");
                Session.Command cmd = session.exec(cmdString);
                System.out.println("command executed");
                
                System.out.println("assign the streams");
                this.inputStream = cmd.getInputStream();
                this.outputStream = cmd.getOutputStream();
                this.errorStream = cmd.getErrorStream();

    // If the section below is un-commented it will work on both the Linux and Windows 
    // machines, but test2 will not see the output.  With the section below commented out
    // it will work on the Windows machine and test2 will see the output of the command,
    // but it will not run to completion on the Linux box, it will just hang.
    
    //        try
    //        {           
    //            InputStreamReader isr = new InputStreamReader(session.getInputStream());
    //            BufferedReader br = new BufferedReader(isr);
    //            String line=null;
    //
    //            while ( (line = br.readLine()) != null)
    //            {
    //                System.out.println(">>" + line);
    //            }
    //
    //        } catch (IOException ioe){
    //            System.out.println(ioe.getMessage());
    //        } 
            
                System.out.println("wait for command to complete");
                while (cmd.getExitStatus() == null){
                
                }
    
                System.out.println("command has completed");
                this.exitStatus = cmd.getExitStatus();
                System.out.println("exit status = " + cmd.getExitStatus());
                
            } catch (Throwable ex) {
                this.exitStatus = 1;
                System.out.println(ex.getMessage());
                
                Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    if (session != null) {
                        session.close();
                    }
                } catch (Throwable ex) {
    
                } 
                
                try {
                    if (ssh != null) {
                        ssh.disconnect();
                    }
                } catch (IOException ex) {
    
                }
            }
        }  
        
        public void waitFor() {
            while (this.exitStatus == null){
                
            }
        }
    }

Here is my test procedure

    import java.io.*;
    import net.schmizz.sshj.SSHClient;
    import net.schmizz.sshj.connection.channel.direct.Session;
    
    /**
     *
     * @author flb
     */
    public class test2 extends SSHClient{
        private static Session session = null;
        private static SSHClient ssh = null;
        
        //public String host = "192.168.1.1";
        public String host = "10.1.1.30";
        public String userId = "sys";
        //public String keyFile = "/u/sms_scripts/lib/backup/nas_rsa";   
        public String keyFile = "nas_rsa";
           
        public static void main(String[] args){
            test2 testProc = new test2(args);
        }
        
        
        private test2 (String[] args) {                           
            SSHExec ssh = new SSHExec();
            System.out.println(System.getProperty("java.version"));
            
            ssh.exec(this.host,this.userId,this.keyFile,"pwd");
            
            try
            {           
                InputStreamReader isr = new InputStreamReader(ssh.inputStream);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
    
                while ( (line = br.readLine()) != null)
                {
                    System.out.println(">" + line);
                }
    
            } catch (IOException ioe){
                System.out.println(ioe.getMessage());
            } 
    
            System.out.println("command has completed");
            System.out.println("exit status = " + ssh.exitStatus);
        }  
    }

What is seems like to me is that for some reason when I try to assign the input stream on the Linux box in test2, I do not get it.  Since I do not get it, it never is emptied and that is causing the ssh command to never complete, since it's input stream is not cleared.  Does anyone have any idea why that might be the case?
