0
我无法在ssh来执行下面的命令得到错误不正确使用,而同样的,我能够执行手动代码给出无法在ssh来执行命令Jsch
public static void main(String[] args) {
String host="";
String user="";
String password="";
//String command1="mml";
String command2="mml hgsdp:msisdn=919051018408";
try{
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session=jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
System.out.println("Connected");
Channel channel=session.openChannel("exec");
//((ChannelExec)channel).setCommand(command1);
((ChannelExec)channel).setCommand(command2);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(in.available()>0){
int i=in.read(tmp, 0, 1024);
if(i<0)break;
System.out.print(new String(tmp, 0, i));
}
if(channel.isClosed()){
System.out.println("exit-status: "+channel.getExitStatus());
break;
}
try{
Thread.sleep(1000);
}catch(Exception ee){}
}
channel.disconnect();
session.disconnect();
System.out.println("DONE");
}catch(Exception e){
e.printStackTrace();
}
}
你可以发布堆栈跟踪吗? – eltabo
错误使用 用法:mml [-a] [-c] [-s | -Q] [-d设备] [-i设备| -I device] [-y lines] mml [-s] [-d device] [-i device | -I设备] [-r时间] [-w时间]命令... mml [-b] [-c] [-s] [-l行] [-r时间] [-w时间] -f文件 退出状态:2 –