Log My environment is Windows with around 8-10 simultaneous pahntom js processes launched from the phantom js cli. I don't bother with getting the PID of the phantom JS process, it's all managed under the hood by commons exec.
CommandLine cmd = new CommandLine(mwProps.getProperty("phantonjs.exec"));
cmd.addArguments(getPhantomJSOptions(mwProps));
cmd.addArguments(new String[] {mwProps.getProperty("phantonjs.rasterizejs"), location, outputFile.getCanonicalPath(),
mwProps.getProperty("phantonjs.outputPaperSize") });
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0); //assume exit code 0 is a successful exit
PumpStreamHandler psh = new PumpStreamHandler(new ExecLogHangler(), new ExecLogHangler());
executor.setStreamHandler(psh);
long timeout = 9*60*1000L;
if(mwProps.getProperty("phantonjs.execTimeout")!=null) {
timeout = Long.parseLong(mwProps.getProperty("phantonjs.execTimeout"));
}
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
executor.setWatchdog(watchdog);
executor.execute(cmd);
public static class ExecLogHangler extends LogOutputStream {
public ExecLogHangler() {
}
@Override
protected void processLine(String line, int logLevel) {
}
}