相关文章推荐
阳刚的蚂蚁  ·  Linux ...·  1 月前    · 
深情的鞭炮  ·  Install .NET Runtime ...·  1 月前    · 
爽快的绿豆  ·  linux kill命令__linux ...·  1 月前    · 
腼腆的烈马  ·  [Anaconda]——Linux下cond ...·  1 周前    · 
气宇轩昂的自行车  ·  关于video-js ...·  8 月前    · 
高大的灌汤包  ·  异常:Error:Execution ...·  1 年前    · 
腼腆的帽子  ·  .NET Core ...·  1 年前    · 




public List<String> executeNewFlow(List<String> commands) {
List<String> rspList = new ArrayList<String>();
Runtime run = Runtime.getRuntime();
try {
Process proc = run.exec("/bin/bash", null, null);
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
for (String line : commands) {
out.println(line);
}
// out.println("cd /home/test");
// out.println("pwd");
// out.println("rm -fr /home/proxy.log");
out.println("exit");// 这个命令必须执行,否则in流不结束。
String rspLine = "";
while ((rspLine = in.readLine()) != null) {
System.out.println(rspLine);
rspList.add(rspLine);
}
proc.waitFor();
in.close();
out.close();
proc.destroy();
} catch (IOException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return rspList;
}