这段代码检查进程是否正常启动。
protected boolean isInstalled(File executable, List<String> args)
{
if (!executable.exists())
return false;
try
{
List<String> cmdLine = new ArrayList<>();
cmdLine.add(new Path(executable.getAbsolutePath()).toOSString());
cmdLine.addAll(args);
Process process = new ProcessBuilder(cmdLine).start();
if (process.waitFor(8, TimeUnit.SECONDS))
{
return (process.exitValue() == 0);
}
else
{
process.destroy();
return false;
}
}
catch (IOException ex)
{
return false;
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
return false;
}
}
当我想检查进程是否正常启动时,是否需要读取流?这个过程是否有可能以这种方式挂起?