[英]linux shell and java
我想向Linux Shell发送命令并使用Java获得它的响应。我该怎么做?
执行这样的过程
Runtime.getRuntime().exec("ls");
...然后您可以获取流程输入流,并使用Reader对其进行读取以获取响应
几周前,我在一个非常类似的问题中写了一堂小课来做到这一点:
该类基本上让您执行以下操作:
ShellExecutor excutor = new ShellExecutor("/bin/bash", "-s");
try {
System.out.println(excutor.execute("ls / | sort -r"));
} catch (IOException e) {
e.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.