Tabnine Logo
org.apache.commons.exec
Code IndexAdd Tabnine to your IDE (free)

How to use org.apache.commons.exec

Best Java code snippets using org.apache.commons.exec (Showing top 20 results out of 1,089)

origin: apache/storm

public static int execCommand(String... command) throws ExecuteException, IOException {
  CommandLine cmd = new CommandLine(command[0]);
  for (int i = 1; i < command.length; i++) {
    cmd.addArgument(command[i]);
  }
  DefaultExecutor exec = new DefaultExecutor();
  return exec.execute(cmd);
}
origin: eirslett/frontend-maven-plugin

private Executor createExecutor(File workingDirectory, long timeoutInSeconds) {
  DefaultExecutor executor = new DefaultExecutor();
  executor.setWorkingDirectory(workingDirectory);
  executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());   // Fixes #41
  if (timeoutInSeconds > 0) {
    executor.setWatchdog(new ExecuteWatchdog(timeoutInSeconds * 1000));
  }
  return executor;
}
origin: stackoverflow.com

 String line = "myCommand.exe";
CommandLine commandLine = CommandLine.parse(line);
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
int exitValue = executor.execute(commandLine);
origin: openhab/openhab1-addons

  cmdLine = new CommandLine(cmdArray[0]);
    cmdLine.addArgument(cmdArray[i], false);
  cmdLine = CommandLine.parse(commandLine);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
Executor executor = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(stdout);
executor.setExitValue(1);
executor.setStreamHandler(streamHandler);
executor.setWatchdog(watchdog);
  executor.execute(cmdLine, resultHandler);
  logger.debug("executed commandLine '{}'", commandLine);
} catch (IOException e) {
  resultHandler.waitFor();
  int exitCode = resultHandler.getExitValue();
  retval = StringUtils.chomp(stdout.toString());
  if (resultHandler.getException() != null) {
    logger.warn("{}", resultHandler.getException().getMessage());
  } else {
    logger.debug("exit code '{}', result '{}'", exitCode, retval);
origin: alibaba/jstorm

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));
PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
executor.setStreamHandler(streamHandler);
    executor.execute(cmd, environment);
  } else {
    executor.execute(cmd, environment, resultHandler);
origin: xuxueli/xxl-job

  PumpStreamHandler streamHandler = new PumpStreamHandler(fileOutputStream, fileOutputStream, null);
  CommandLine commandline = new CommandLine(command);
  commandline.addArgument(scriptFile);
  if (params!=null && params.length>0) {
    commandline.addArguments(params);
  DefaultExecutor exec = new DefaultExecutor();
  exec.setExitValues(null);
  exec.setStreamHandler(streamHandler);
  int exitValue = exec.execute(commandline);  // exit code: 0=success, 1=error
  return exitValue;
} catch (Exception e) {
origin: mulesoft/mule

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, false);
 DefaultExecutor executor = new DefaultExecutor();
 ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
 executor.setWatchdog(watchdog);
 executor.setStreamHandler(new PumpStreamHandler());
 return doExecution(executor, commandLine, newEnv);
}
origin: apache/hive

private ExecBean auxRun(String program, List<String> args, Map<String, String> env)
 throws NotAuthorizedException, ExecuteException, IOException {
 DefaultExecutor executor = new DefaultExecutor();
 executor.setExitValues(null);
 ByteArrayOutputStream outStream = new MaxByteArrayOutputStream(nbytes);
 ByteArrayOutputStream errStream = new MaxByteArrayOutputStream(nbytes);
 executor.setStreamHandler(new PumpStreamHandler(outStream, errStream));
 ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
 executor.setWatchdog(watchdog);
 ExecBean res = new ExecBean();
 res.exitcode = executor.execute(cmd, execEnv(env));
 res.stderr = errStream.toString(enc);
 try {
  watchdog.checkException();
 if(watchdog.killedProcess()) {
  String msg = " was terminated due to timeout(" + timeout + "ms).  See " + AppConfig
      .EXEC_TIMEOUT_NAME + " property"; 
origin: BroadleafCommerce/BroadleafCommerce

  protected String executeExternalJavaProcess(Class<?> mainClass) throws IOException {
    String classpath = MvelTestUtils.getClassPath();
    
    //See javadoc on MvelOverloadFailureReproduction for description of why we need to execute the test in a new JVM
    CommandLine cmdLine = new CommandLine("java");
    cmdLine.addArgument("-cp");
    cmdLine.addArgument(classpath, true);
    cmdLine.addArgument(mainClass.getName());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Executor executor = new DefaultExecutor();
    executor.setStreamHandler(new PumpStreamHandler(baos));
    try {
      executor.execute(cmdLine, new HashMap<String, String>());
    } catch (IOException e) {
      throw new IOException(new String(baos.toByteArray()));
    }
    return new String(baos.toByteArray());
  }
}
origin: stackoverflow.com

 import java.io.ByteArrayOutputStream;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.Executor;
import org.apache.commons.exec.PumpStreamHandler;

public String execToString(String command) throws Exception {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  CommandLine commandline = CommandLine.parse(command);
  DefaultExecutor exec = new DefaultExecutor();
  PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
  exec.setStreamHandler(streamHandler);
  exec.execute(commandline);
  return(outputStream.toString());
}
origin: elasticjob/elastic-job-lite

  private void executeScript(final ShardingContext shardingContext, final String scriptCommandLine) {
    CommandLine commandLine = CommandLine.parse(scriptCommandLine);
    commandLine.addArgument(GsonFactory.getGson().toJson(shardingContext), false);
    try {
      new DefaultExecutor().execute(commandLine);
    } catch (final IOException ex) {
      throw new JobConfigurationException("Execute script failure.", ex);
    }
  }
}
origin: eirslett/frontend-maven-plugin

private CommandLine createCommandLine(List<String> command) {
  CommandLine commmandLine = new CommandLine(command.get(0));
  for (int i = 1;i < command.size();i++) {
    String argument = command.get(i);
    commmandLine.addArgument(argument, false);
  }
  return commmandLine;
}
origin: eirslett/frontend-maven-plugin

private int execute(final Logger logger, final OutputStream stdout, final OutputStream stderr)
    throws ProcessExecutionException {
  logger.debug("Executing command line {}", commandLine);
  try {
    ExecuteStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr);
    executor.setStreamHandler(streamHandler);
    int exitValue = executor.execute(commandLine, environment);
    logger.debug("Exit value {}", exitValue);
    return exitValue;
  } catch (ExecuteException e) {
    if (executor.getWatchdog() != null && executor.getWatchdog().killedProcess()) {
      throw new ProcessExecutionException("Process killed after timeout");
    }
    throw new ProcessExecutionException(e);
  } catch (IOException e) {
    throw new ProcessExecutionException(e);
  }
}
origin: org.apache.commons/commons-exec

/**
 * @see org.apache.commons.exec.Executor#execute(CommandLine,
 *      org.apache.commons.exec.ExecuteResultHandler)
 */
public void execute(final CommandLine command, final ExecuteResultHandler handler)
    throws ExecuteException, IOException {
  execute(command, null, handler);
}
origin: org.apache.commons/commons-exec

/**
 * Add multiple arguments. Handles parsing of quotes and whitespace.
 * Please note that the parsing can have undesired side-effects therefore
 * it is recommended to build the command line incrementally.
 * 
 * @param addArguments An string containing multiple arguments. 
 * @return The command line itself
 */
public CommandLine addArguments(final String addArguments) {
  return this.addArguments(addArguments, true);
}
origin: org.apache.commons/commons-exec

  public void run()
  {
    int exitValue = Executor.INVALID_EXITVALUE;
    try {
      exitValue = executeInternal(command, environment, workingDirectory, streamHandler);
      handler.onProcessComplete(exitValue);
    } catch (final ExecuteException e) {
      handler.onProcessFailed(e);
    } catch (final Exception e) {
      handler.onProcessFailed(new ExecuteException("Execution failed", exitValue, e));
    }
  }
};
origin: org.apache.commons/commons-exec

/**
 * Logs a line to the log system of the user.
 *
 * @param line
 *            the line to log.
 */
protected void processLine(final String line) {
  processLine(line, level);
}
origin: alibaba/jstorm

CommandLine cmd = new CommandLine(cmdlist[0]);
for (String cmdItem : cmdlist) {
  if (StringUtils.isBlank(cmdItem) == false) {
    cmd.addArgument(cmdItem);
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0);
if (StringUtils.isBlank(workDir) == false) {
  executor.setWorkingDirectory(new File(workDir));
PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
if (streamHandler != null) {
  executor.setStreamHandler(streamHandler);
    executor.execute(cmd, environment);
  } else {
    executor.execute(cmd, environment, resultHandler);
origin: alibaba/mdrill

public static void exec_command(String command) throws ExecuteException,
    IOException {
  String[] cmdlist = command.split(" ");
  CommandLine cmd = new CommandLine(cmdlist[0]);
  for (int i = 1; i < cmdlist.length; i++) {
    cmd.addArgument(cmdlist[i]);
  }
  DefaultExecutor exec = new DefaultExecutor();
  exec.execute(cmd);
}
origin: apache/hive

private CommandLine makeCommandLine(String program,
         List<String> args)
 throws NotAuthorizedException, IOException {
 String path = validateProgram(program);
 CommandLine cmd = new CommandLine(path);
 if (args != null)
  for (String arg : args)
   cmd.addArgument(arg, false);
 return cmd;
}
org.apache.commons.exec

Most used classes

  • CommandLine
    CommandLine objects help handling command lines specifying processes to execute. The class can be us
  • DefaultExecutor
    The default class to start a subprocess. The implementation allows to * set a current working dir
  • PumpStreamHandler
    Copies standard output and error of sub-processes to standard output and error of the parent process
  • ExecuteWatchdog
    Destroys a process running for too long. For example: ExecuteWatchdog watchdog = new ExecuteWatchdo
  • Executor
    The main abstraction to start an external process. The interface allows to * set a current workin
  • ExecuteException,
  • ShutdownHookProcessDestroyer,
  • EnvironmentUtils,
  • OS,
  • StreamPumper,
  • DaemonExecutor,
  • CommandLauncher,
  • CommandLauncherFactory,
  • StringUtils,
  • InputStreamPumper,
  • LogOutputStream,
  • DebugUtils,
  • MapUtils,
  • CommandLine$Argument
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now