Hi,
I am trying to implement an apps that send multiple commands one at a time
to a remote system. However, after I execute the first command, I get error.
From the debug trace, the error found:
DEBUG: Caught an exception, leaving main loop due to End of IO Stream
ReadDEBUG: Disconnecting from cheesoon.revenuenetwork.net port 22
Below is part of the codes. Summary of my codes is that my second command, I
re-initiate channel object and re-used the session object. Is that the right
way to things? I test it and its not working says session has been closed due
to the above DEBUG reason. If I re-initiate the session, then its ok. Is this
the right way?
//FIRST commandSession session=jsch.getSession(user, host, 22);
session.connect();
command = "display version"; Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err); InputStream
in=channel.getInputStream(); OutputStream out = channel.getOutputStream();
String versionDesc = null; String outgoing = null; String temp =
null; channel.connect(); byte[] tmp=new byte[1024];
while(true){ while(in.available()>0){ int i=in.read(tmp, 0,
1024); if(i<0) break; temp = new String(tmp, 0, i);
if (versionDesc == null) { temp.replaceAll("^\\s+", "");
temp.replaceAll("^(\\r\\n)+", ""); versionDesc = temp;
System.out.println(versionDesc); } else versionDesc += temp;
outgoing = new String (" "); // keeps listing the config values
out.write(outgoing.getBytes()); out.flush(); }
if(channel.isClosed()){ if(in.available()>0) continue;
System.out.println("exit-status: "+channel.getExitStatus()); break;
} try{Thread.sleep(1000);}catch(Exception ee){} }
channel.disconnect(); //session.disconnect();
//SECOND COMMANDcommand = "display current configuration"; Channel
channel=session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err); InputStream
in=channel.getInputStream(); OutputStream out = channel.getOutputStream();
String versionDesc = null; String outgoing = null; String temp =
null; channel.connect(); byte[] tmp=new byte[1024];
while(true){ while(in.available()>0){ int i=in.read(tmp, 0,
1024); if(i<0) break; temp = new String(tmp, 0, i);
if (versionDesc == null) { temp.replaceAll("^\\s+", "");
temp.replaceAll("^(\\r\\n)+", ""); versionDesc = temp;
System.out.println(versionDesc); } else versionDesc += temp;
outgoing = new String (" "); // keeps listing the config values
out.write(outgoing.getBytes()); out.flush(); }
if(channel.isClosed()){ if(in.available()>0) continue;
System.out.println("exit-status: "+channel.getExitStatus()); break;
} try{Thread.sleep(1000);}catch(Exception ee){} }
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users