/** * Spawns a new process using the Java Runtime API. * * @see SystemInfo#executeProcess(ProcessExecution) */ public ProcessExecutionResults executeProcess(ProcessExecution processExecution) { ProcessToStart process = new ProcessToStart(); ProcessExecutionResults executionResults = new ProcessExecutionResults(); process.setProgramExecutable(processExecution.getExecutable()); process.setCheckExecutableExists(processExecution.isCheckExecutableExists()); process.setArguments(processExecution.getArgumentsAsArray()); process.setEnvironment(processExecution.getEnvironmentVariablesAsArray()); process.setWorkingDirectory(processExecution.getWorkingDirectory()); process.setWaitForExit(Long.valueOf(processExecution.getWaitForCompletion())); process.setCaptureOutput(Boolean.valueOf(processExecution.getCaptureMode().isCapture())); process.setKillOnTimeout(Boolean.valueOf(processExecution.isKillOnTimeout())); ProcessExecutionOutputStream outputStream = processExecution.getCaptureMode().createOutputStream(); process.setOutputStream(outputStream); executionResults.setCapturedOutputStream(outputStream); ProcessExecutorResults javaExecResults = javaExec.execute(process); executionResults.setExitCode(javaExecResults.getExitCode()); executionResults.setError(javaExecResults.getError()); executionResults.setProcess(javaExecResults.getProcess()); return executionResults; }
/** * The process's output will be captured and returned in the results. This may be ignored if * <code>waitForCompletion</code> is 0 or less. Process output will be logged into agent.log and at the same time * captured into memory. With <code>limit</code> parameter you can set maximum memory buffer to be captured (and possibly returned) * captured output size. If the process writes more output, it will only be redirected to agent.log. * * @param limit in Bytes (if given value < 0, it's ignored and default 2MB is used instead) * @return captureMode */ public static CaptureMode agentLog(int limit) { return new CaptureMode(true, true, limit); }
/** * The process's output will be captured and returned in the results. This may be ignored if * <code>waitForCompletion</code> is 0 or less. By default capturing to memory is limited to 2MB of * process output. If the process writes more output, it will be ignored. * @return captureMode */ public static CaptureMode memory() { return new CaptureMode(true); }
/** * The process's output is *not* captured, this is the default. * @return captureMode */ public static CaptureMode none() { return new CaptureMode(false); }
/** * The process's output will be captured and returned in the results. This may be ignored if * <code>waitForCompletion</code> is 0 or less. With <code>limit</code> parameter you can set maximum captured output size. * If the process writes more output, it will be ignored. * * @param limit in Bytes (if given value < 0, it's ignored and default 2MB is used instead) * @return captureMode */ public static CaptureMode memory(int limit) { return new CaptureMode(true, limit); }
/** * If <code>true</code>, the process's output will be captured and returned in the results. This may be ignored if * <code>waitForCompletion</code> is 0 or less. Be careful setting this to <code>true</code>, you must ensure that * the process will not write a lot of output - you might run out of memory if the process is a long-lived daemon * process that outputs a lot of log messages, for example. By default, output is *not* captured. * @deprecated @see {@link #setCaptureMode(CaptureMode)} * @param captureOutput whether or not this process's output (stdout+stderr) should be captured and returned in the * results */ public void setCaptureOutput(boolean captureOutput) { this.captureMode = captureOutput ? CaptureMode.memory() : CaptureMode.none(); }
/** * * @return whether capture process output * @deprecated */ public boolean isCaptureOutput() { return this.captureMode.isCapture(); }
/** * The process's output will be captured and returned in the results. This may be ignored if * <code>waitForCompletion</code> is 0 or less. Process output will be redirected to agent.log and at the same time * captured into memory. By default capturing to memory is limited to 2MB of process output. If the process writes more output, * it will only be redirected to agent.log. * * @return captureMode */ public static CaptureMode agentLog() { return new CaptureMode(true, true, -1); }