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 –