windows 使用 Java 在远程系统上执行批处理文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7346907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:01:50  来源:igfitidea点击:

Executing batch file on remote system using Java

javawindows

提问by Abhinav Garg

How to execute a batch file located on Windows remote system? Batch file should run on remote system.

如何执行位于 Windows 远程系统上的批处理文件?批处理文件应该在远程系统上运行。

回答by Santosh

Abhinav, For your problem I see RMI is the quickest possible solution

Abhinav,对于您的问题,我认为 RMI 是最快的解决方案

  1. Check out the basics from these links (1,2)
  2. Start the server from where you want to run the batch
  3. In the Remote object on the server side Use Runtime.getRuntime().exec()to run your batch.
  4. From the client machine give call to this remote object and method.
  1. 从这些链接 ( 1, 2)查看基础知识
  2. 从要运行批处理的位置启动服务器
  3. 在服务器端的 Remote 对象中Runtime.getRuntime().exec()用于运行您的批处理。
  4. 从客户端机器调用这个远程对象和方法。

回答by Peter Lawrey

Another approach is to use SSH like sshj. This only requires the remote system to have SSH installed and is more secure than RMI.

另一种方法是像 sshj 一样使用 SSH。这只需要远程系统安装 SSH 并且比 RMI 更安全。

回答by nIKUNJ

You can use Jschand Expect4jfor executing commands on remote machine(window/Linux). Further more, if your system allows, transfer the batch file on remote machine using some FTP utility like Apache Commons Netand then execute commands that executes the script.

您可以使用JschExpect4j在远程机器(window/Linux)上执行命令。此外,如果您的系统允许,请使用某些 FTP 实用程序(如Apache Commons Net)在远程计算机上传输批处理文件,然后执行执行脚本的命令。