Sometimes with the few servers, The data read from input stream and error 
stream are 0 bytes causing JSch to hang in read.

The code is as follows:

        // Set the command
        channel = session.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);
        InputStream in = channel.getInputStream();

        InputStream inExt = channel.getExtInputStream();
        BufferedReader brErr = new BufferedReader(new InputStreamReader(inExt));
        BufferedWriter bufWriter = new BufferedWriter(new 
OutputStreamWriter(channel.getOutputStream()));
        channel.connect();
        // LOOP FOR FIXED TIME PERIOD until data is available 
        // Changing this code to wait indefinitely until channel is closed is 
also hangning since the channel is never gettting closed.
        while (fixed time) {                      
                if (channel.isClosed() || data in any stream)    
                    break;
                Thread.sleep(100);
        }
     
        System.out.println("Stdout Bytes available : " + in.available());
        System.out.println("StdErr Bytes available : " + inExt.available());
        // The data available here is 0 bytes on both the streams causing the 
subsequent read on Stream to hang.
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            if (br != null)  {
                String line = null;
                while ((line = br.readLine()) != null){
                    System.out.println(line);
                }
            }
Performing ssh directly to the server works well. This problem is while running 
with the Jsch code. 
Why does the data from servers is 0 bytes on both the streams. How to write 
code such that data from servers appear correctly on streams? 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to