如何在java程序中调用linux命令或者shell脚本
1个回答
展开全部
依赖 trilead.jar
public static void main(String[] args) {
Connection connection = new Connection("..ip..");
try {
connection.connect();
connection.authenticateWithPassword("用户名", "密码");
Session session = connection.openSession();
session.execCommand("command串");
String line = null;
BufferedReader errReader = new BufferedReader(new InputStreamReader(session.getStderr()));
while ((line = errReader.readLine()) != null) {
System.out.println(line);
}
System.out.println(session.getExitStatus());
session.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
connection.close();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |