1

在这里,我正在使用以下代码从本地 Windows 机器上执行远程 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();
4

1 回答 1

0

您需要在主机 (String host = ip) windows 上安装 cygwin 才能使用 jsch。关注此站点:https ://dbaportal.eu/2015/03/05/installing-openssh-cygwin-1-7-35-on-windows-2012-r2/

于 2016-08-09T07:18:04.137 回答