我有以下运行批处理文件的java代码片段(根据标志重命名文件)。此代码正常工作。但是,当我评论该行时while( isRunning(p) ) {}
,它就不起作用了。任何人都可以给出任何理由吗?
public static void main(String[] args) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder( fileManipulatorScriptLocation, "Rename_File", "a.txt", "b.txt" );
pb.directory( new File(targetDirectory) );
Process p = pb.start();
while( isRunning(p) ) {}
}
public static boolean isRunning(Process process) {
try {
process.exitValue();
return false;
} catch (IllegalThreadStateException e) {
return true;
}
}