process.waitFor()暂停调用线程

时间:2012-02-24 16:58:02

标签: java runtime.exec

我从我的java代码调用脚本如下

public void executeScript(String data) throws IOException, Exception 
{
  String[] cmd = {"/bin/bash ", "simulator.sh " };
  cmd[1] = cmd[1] + data;

  Runtime run = Runtime.getRuntime();

  Process proc = run.exec(cmd[0] + cmd[1]);

  ......

  proc.waitFor();

  .........

  //read any errors from the attempted command
  InputStreamReader iStreamReader = new InputStreamReader(proc.getErrorStream());
  BufferedReader stdError = new BufferedReader(iStreamReader);
  String s;
  while ((s = stdError.readLine()) != null) { .... }

  proc.getErrorStream().close();
  proc.getInputStream().close();
  proc.getOutputStream().close();
  proc.destroy();


}

现在,这个代码每200毫秒在一个循环中被调用,但是调用线程等待进程完成的时间超过这个时间。我不希望调用线程等待进程完成。

调用线程是否有可能不在此进程上等待,因为调用线程不需要脚本的输出?

0 个答案:

没有答案