use of org.apache.commons.exec.DefaultExecutor in project mule by mulesoft.
the class AbstractOSController method executeSyncCommand.
private int executeSyncCommand(String command, String[] args, Map<Object, Object> newEnv, int timeout) throws MuleControllerException {
CommandLine commandLine = new CommandLine(muleBin);
commandLine.addArgument(command);
commandLine.addArguments(args);
DefaultExecutor executor = new DefaultExecutor();
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
executor.setWatchdog(watchdog);
executor.setStreamHandler(new PumpStreamHandler());
return doExecution(executor, commandLine, newEnv);
}
use of org.apache.commons.exec.DefaultExecutor in project mule by mulesoft.
the class MuleUtils method executeCommand.
public static int executeCommand(String command, String... envVars) throws IOException {
CommandLine cmdLine = CommandLine.parse(command);
DefaultExecutor executor = new DefaultExecutor();
Map<String, String> env = addEnvProperties(envVars);
ExecuteWatchdog watchDog = new ExecuteWatchdog(TIMEOUT);
executor.setWatchdog(watchDog);
executor.setStreamHandler(new PumpStreamHandler());
int result = executor.execute(cmdLine, env);
if (executor.isFailure(result)) {
if (watchDog.killedProcess()) {
throw new RuntimeException("Reached timeout while running: " + cmdLine);
}
throw new RuntimeException("Process failed with return code [" + result + "]: " + cmdLine);
}
return result;
}
use of org.apache.commons.exec.DefaultExecutor in project jbpm-work-items by kiegroup.
the class ExecWorkItemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
String command = (String) workItem.getParameter("Command");
CommandLine commandLine = CommandLine.parse(command);
DefaultExecutor executor = new DefaultExecutor();
try {
executor.execute(commandLine);
manager.completeWorkItem(workItem.getId(), null);
} catch (Throwable t) {
handleException(t);
}
}
use of org.apache.commons.exec.DefaultExecutor in project jstorm by alibaba.
the class JStormUtils method launchProcess.
/**
* If it is backend, please set resultHandler, such as DefaultExecuteResultHandler
* If it is frontend, ByteArrayOutputStream.toString will return the calling result
* <p>
* This function will ignore whether the command is successfully executed or not
*
* @param command command to be executed
* @param environment env vars
* @param workDir working directory
* @param resultHandler exec result handler
* @return output stream
* @throws IOException
*/
@Deprecated
public static ByteArrayOutputStream launchProcess(String command, final Map environment, final String workDir, ExecuteResultHandler resultHandler) throws IOException {
String[] cmdlist = command.split(" ");
CommandLine cmd = new CommandLine(cmdlist[0]);
for (String cmdItem : cmdlist) {
if (!StringUtils.isBlank(cmdItem)) {
cmd.addArgument(cmdItem);
}
}
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0);
if (!StringUtils.isBlank(workDir)) {
executor.setWorkingDirectory(new File(workDir));
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
executor.setStreamHandler(streamHandler);
try {
if (resultHandler == null) {
executor.execute(cmd, environment);
} else {
executor.execute(cmd, environment, resultHandler);
}
} catch (ExecuteException ignored) {
}
return out;
}
use of org.apache.commons.exec.DefaultExecutor in project sonar-scanner-jenkins by SonarSource.
the class JenkinsWrapper method createExecutor.
@VisibleForTesting
DefaultExecutor createExecutor(ExecuteWatchdog watchDog) {
DefaultExecutor newExecutor = new DefaultExecutor();
newExecutor.setWatchdog(watchDog);
newExecutor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
return newExecutor;
}
Aggregations