Apache Commons Exec 是 Apache 上的一个 Java 项目,提供一些常用的方法用来执行外部进程,如下面代码所示:
String line = "AcroRd32.exe /p /h " + file.getAbsolutePath(); CommandLine commandLine = CommandLine.parse(line); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(commandLine);