如何在 Windows 上使用 java 执行 linux 命令? [英] how execute linux command using java on windows?

查看:49
本文介绍了如何在 Windows 上使用 java 执行 linux 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Windows 上使用 java 在单独的 Linux 机器上执行 bash 命令.

I need execute bash commands on a separate Linux machine using java on Windows.

我需要从指定目录运行可执行文件,比如

I need run executable file from specified directory, like

cd /home/bin

我该怎么做?

推荐答案

找了好久,终于找到有用的信息了.请按照链接如何运行 SSH 命令在使用 Java 的远程系统上?"

After long hours, I finally found useful information. please follow link "How do I run SSH commands on remote system using Java?"

也使用来自http://www.ganymed.ethz.ch/ssh2/"链接.它是任何人在 windows 环境下从 java 代码执行 ssh 命令所需的 jar.还有其他方法.而且大多数 jars 我没有发现它们有用,特别是当你想自动化用户身份验证以访问 linux 环境时.

Also use jar from "http://www.ganymed.ethz.ch/ssh2/" the link. It is the jar required for any person to execute ssh commands from java code in windows environment. There are other ways too. And most jars I didn't find them useful, especially when you want to automate user authentication to access linux environment.

注意,直接传递密码(ssh 密码)是不合适的做事方式.许多专家在其他几个线程中提出了建议.但这个简单的解决方案适用于不关心安全性的人.

Note, passing directly the password (ssh password) is not appropriate way of doing things.And many experts suggested in few other threads.But this simple solution works for someone who is not concerned about security.

这篇关于如何在 Windows 上使用 java 执行 linux 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆