java 如何从Java自动化腻子

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6408616/
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-10-30 15:47:25  来源:igfitidea点击:

How to automate putty from java

javaputty

提问by Sumit Jain

Is there any way so that i can automate putty from java class including running,login and sending unix commands one by one to executeand.

有什么方法可以让我从java类自动执行putty,包括运行、登录和发送unix命令一一执行和。

I have a some specific command list that i wan't to execute on server for that i wan't to automate putty.

我有一些特定的命令列表,我不想在服务器上执行,因为我不想自动化腻子。

回答by Thorbj?rn Ravn Andersen

You do not want to run putty as it expects a GUI environment which is not available when launched from Java.

您不想运行 putty,因为它期望从 Java 启动时不可用的 GUI 环境。

You need a suitable ssh library which can handle the connection and send commands and received responses. This allow you to fully script it from inside java.

您需要一个合适的 ssh 库来处理连接并发送命令和接收响应。这允许您从 Java 内部完全编写脚本。

I have heard good things about jsch - http://www.jcraft.com/jsch/- but have not used it myself.

我听说过关于 jsch 的好消息 - http://www.jcraft.com/jsch/- 但我自己没有使用过。

回答by Persimmonium

maybe you could automate it at command line level, using expectj

也许你可以在命令行级别自动执行它,使用expectj

回答by Harry B

The easiest way is to write a .bat file which will have your putty login details and then a text file which will have your commands. Then you could run that .bat file which will open putty and run all the commands you have in the list.

最简单的方法是编写一个 .bat 文件,其中包含您的 Putty 登录详细信息,然后编写一个包含您的命令的文本文件。然后您可以运行该 .bat 文件,该文件将打开 putty 并运行您在列表中的所有命令。

But, after doing all this my requirement has changed to having a independent GUI to manage my server, so I would agree with Ravn Anderson but that would take a lot of effort.

但是,在完成所有这些之后,我的要求变成了拥有一个独立的 GUI 来管理我的服务器,所以我同意 Ravn Anderson 的观点,但这需要付出很多努力。

So it all depends what sort of application you need.

所以这完全取决于你需要什么样的应用程序。