1
這裏我使用下面的代碼從本地Windows機器執行遠程Windows服務器上的命令。但我的錯誤爲JSCH在Windows機器上執行命令並取出輸出
「無法執行遠程系統上的命令或shell:無法執行 執行過程。」
任何人可以幫助我在這裏要來這個問題的呢?
String user = username;
String pass = password;
String host = ip;
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setPassword(pass);
session.connect();
Channel channel = session.openChannel("exec");
channel.connect();
((ChannelExec)channel).setCommand("cmd.exe /c \"echo %cd%\"");
InputStream outputstream_from_the_channel = channel.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(outputstream_from_the_channel));
String jarOutput;
System.out.println("1");
while ((jarOutput = reader.readLine()) != null) {
System.out.println("Inside while loop");
System.out.println(jarOutput + "\n");
}
System.out.println("2");
reader.close();
你只需要移動'連接'set命令後()'方法()' –