[英]opening a shell and interact with using Java
可行解决方案的示例几乎如下所示
Process process;
rt = Runtime.getRuntime();
try
{
process = rt.exec(new String[]{"bash","-c","ls -al /home/"});
log.warn("message to display");
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
log.warn(line);
}
int exitVal = process.waitFor();
log.warn("Exited with error code : "+ exitVal);
}
catch (IOException e)
{
log.warn("IO Execption 1 Happen : " + e.getMessage());
}
catch (Exception e)
{
log.warn("Execption Happen : " + e.getMessage());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.