public void execute(CommandLine cmd, @Nullable File workingDirectory) throws InterruptedException, IOException { LOG.info("executing command {}", cmd.toString()); final ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000); final Executor executor = new org.apache.commons.exec.DefaultExecutor(); executor.setWatchdog(watchdog); if (workingDirectory != null) { executor.setWorkingDirectory(workingDirectory); } LOG.debug("workdir: {}", executor.getWorkingDirectory()); final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ByteArrayOutputStream err = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(out, err)); executor.execute(cmd, resultHandler); resultHandler.waitFor(); final int exitCode = resultHandler.getExitValue(); if (out.size() > 0) { LOG.info(out.toString()); } if (exitCode != 0) { throw new IOException(err.size() == 0 ? "command '" + cmd + "' didn't succeed" : err.toString()); } } }
/** * Get an Executor that will run in the given directory with a watchdog set * for the timeout. * * @param workDir * The working directory for the process * @return An executor. */ protected Executor getExecutor(File workDir) { Executor executor= new DefaultExecutor(); executor.setWorkingDirectory(workDir); if (timeout > 0) { ExecuteWatchdog watchdog= new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); } return executor; }
executor.setWorkingDirectory(workFolder);
executor.setWorkingDirectory(workFolder);
executor.setExitValue(0); executor.setWatchdog(watchdog); executor.setWorkingDirectory(pugTemp); executor.execute(cmdLine, resultHandler);
if (workingDir != null) { LOG.info("working directory is " + workingDir.toString()); executor.setWorkingDirectory(workingDir);
.addArgument("./"); this.executor.setWorkingDirectory(jobDir); .addArgument(localArchiveFile.getCanonicalPath()); this.executor.setWorkingDirectory(jobDir); log.debug("Delete command: {}", deleteCommand); this.executor.execute(deleteCommand);
final Executor e = new DefaultExecutor(); if (this.workingDirectory != null) { e.setWorkingDirectory(this.workingDirectory);
final Executor e = new DefaultExecutor(); if (this.workingDirectory != null) { e.setWorkingDirectory(this.workingDirectory);
public void run(Context context) { try (OutputStream out = outStream(context); OutputStream err = errStream(context)) { CommandLine cli = CommandLine .parse(String.format("%s/%s", getProcEnvironment().get(CIRCUS_TRAIN_HOME_ENV_VAR), CIRCUS_TRAIN_HOME_SCRIPT)); cli.addArgument("--config=" + context.getConfigLocation()); if (!StringUtils.isEmpty(context.getCircusTrainConfigLocation())) { cli.addArgument("--config=" + context.getCircusTrainConfigLocation()); } Executor executor = new DefaultExecutor(); executor.setWorkingDirectory(new File(context.getWorkspace())); executor.setStreamHandler(new PumpStreamHandler(out, err)); log.debug("Executing {} with environment {}", cli, getProcEnvironment()); int returnValue = executor.execute(cli, getProcEnvironment()); log.debug("Command exited with value {} ", returnValue); if (returnValue != 0) { throw new CircusTrainException("Circus Train exited with error value " + returnValue); } } catch (Throwable e) { log.error("Unable to execute Circus Train", e); } }
exec.setWorkingDirectory( workingDirectory ); fillSuccessCodes( exec );
exec.setWorkingDirectory( workingDirectory ); fillSuccessCodes( exec );
private static void internalExecute(CommandLine cmdLine, OutputStream outputStream, File workingDirectory) throws IOException { Executor executor = getExecutor(); ExecuteWatchdog watchdog = getExecuteWatchdog(); executor.setWatchdog(watchdog); if (workingDirectory != null) { executor.setWorkingDirectory(workingDirectory); } // set allowed exit values (0 is actually the default) executor.setExitValue(0); PumpStreamHandler psh = new PumpStreamHandler(outputStream); executor.setStreamHandler(psh); executor.execute(cmdLine); if (watchdog.killedProcess()) { throw new ExecuteException(String.format("Watchdog killed Sencha Cmd process after %s ms.", MAX_EXECUTION_TIME), 0); } }
executor.setExitValue(0); executor.setWatchdog(watchdog); executor.setWorkingDirectory(pugTemp); executor.execute(cmdLine, resultHandler);
exec.setWorkingDirectory(getWorkingDirectory()); ShutdownHookProcessDestroyer destroyer = new ShutdownHookProcessDestroyer(); exec.setProcessDestroyer(destroyer);
private static Executor createExecutor(LineConsumer consoleLogHandler, CommandLine command, File projectRoot, ExecuteWatchdog watchDog) { Executor executor = new DefaultExecutor(); executor.setWorkingDirectory(projectRoot); executor.setWatchdog(watchDog); executor.setStreamHandler(new PumpStreamHandler(new WriterOutputStream(new WriterToOutputBridge(consoleLogHandler)))); consoleLogHandler.consumeLine(fullPath(executor.getWorkingDirectory()) + "> " + String.join(" ", command.toStrings()) + LINE_SEPARATOR); return executor; }
executor.setWorkingDirectory(pd.getWorkingDirectory());
executor.setWorkingDirectory(pd.getWorkingDirectory());
@Override public CommandRunResult runCommand(File workingDirectory, String command, String... arguments) { long start = System.currentTimeMillis(); ExecuteWatchdog watchdog = createWatchdog(); CommonsExecProcOutputBuffer buffer = new CommonsExecProcOutputBuffer(); Executor executor = createExecutor(buffer, watchdog); CommandLine commandLine = createCommandLine(command, arguments); int exitCode; IOException exception; log(INFO, "Setting working directory to: " + quote(workingDirectory) + '.'); String argumentsString = ArrayUtils.printQuoted(arguments, ", ", " and "); try { if (workingDirectory != null) { executor.setWorkingDirectory(workingDirectory); // TODO: Error handling } log(INFO, "Executing command " + quote(command) + " with argument(s) " + argumentsString + '.'); exitCode = executor.execute(commandLine); exception = null; } catch (IOException cause) { exitCode = -1; exception = cause; } return createResult(start, buffer, exitCode, exception); }