I have some questions.
I want to run some commands by jsch.
commands like this:
"ls;error command;dir;"
IF the commands include one error command.
how can the other commands run continue?
how can I config the jsch?
IF I want to the other commands terminal, how can I config the jsch?
My code like this:
public static String sshExecute(String host, String user, String pwd,
String command) {
System.getProperty("os.name");
StringBuffer sb = new StringBuffer();
try {
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
session.setPassword(pwd);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand(command);
InputStream in = channel.getInputStream();
channel.connect();
int nextChar;
while (true) {
while ((nextChar = in.read()) != -1) {
sb.append((char) nextChar);
}
if (channel.isClosed()) {
System.out.println("exit-status: "
+ channel.getExitStatus());
break;
}
try {
// Thread.sleep(1000);
}
catch (Exception ee) {
}
}
channel.disconnect();
session.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users