我想使用Process
:
ProcessBuilder
system.out.println(m_sizeOfEnv); // 2
Process process;
for(int i =0 ; i < m_sizeOfEnv; i++){
ProcessBuilder pb = new ProcessBuilder(pathTo); //path to .sh file
process = pb.start();
BufferReader br = new BufferReader(new InputStreamReadser (process.getInputStream())); // print only once
String line = null;
while((line = br.readLine())!=null ){
system.out.println(line); // prints the process output
}
process.destroy();
}
循环运行m_sizeOfEnv
次,但该过程只运行一次。
为什么?