浏览 21403 次
该帖已经被评为精华帖
|
|
---|---|
作者 | 正文 |
发表时间:2003-10-12
public static int doWaitFor(Process p); { int exitValue = -1; // returned to caller when p is finished try { InputStream in = p.getInputStream();; InputStream err = p.getErrorStream();; boolean finished = false; // Set to true when p is finished while(!finished); { try { while( in.available(); > 0); { // Print the output of our system call Character c = new Character( (char); in.read(););; System.out.print( c);; } while( err.available(); > 0); { // Print the output of our system call Character c = new Character( (char); err.read(););; System.out.print( c);; } // Ask the process for its exitValue. If the process // is not finished, an IllegalThreadStateException // is thrown. If it is finished, we fall through and // the variable finished is set to true. exitValue = p.exitValue();; finished = true; } catch (IllegalThreadStateException e); { // Process is not finished yet; // Sleep a little to save on CPU cycles Thread.currentThread();.sleep(500);; } } } catch (Exception e); { // unexpected exception! print it out for debugging... System.err.println( "doWaitFor();: unexpected exception - " + e.getMessage(););; } // return completion status to caller return exitValue; } 这个问题不能说是 JVM 的 Bug,具体的原因请看: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |