Java - 在循环中运行进程

时间:2016-03-31 11:25:35

标签: java process processbuilder

我想使用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次,但该过程只运行一次。 为什么?

0 个答案:

没有答案