/** * Returns the command line as an array of strings. * * @return The command line as an string array */ public String[] toStrings() { final String[] result = new String[arguments.size() + 1]; result[0] = this.getExecutable(); System.arraycopy(getArguments(), 0, result, 1, result.length-1); return result; }
/** * Copy constructor. * * @param other the instance to copy */ public CommandLine(final CommandLine other) { this.executable = other.getExecutable(); this.isFile = other.isFile(); this.arguments.addAll(other.arguments); if (other.getSubstitutionMap() != null) { final Map<String, Object> omap = new HashMap<String, Object>(); this.substitutionMap = omap; final Iterator<String> iterator = other.substitutionMap.keySet().iterator(); while (iterator.hasNext()) { final String key = iterator.next(); omap.put(key, other.getSubstitutionMap().get(key)); } } }
protected int doExecution(DefaultExecutor executor, CommandLine commandLine, Map<Object, Object> env) { try { final StringJoiner paramsJoiner = new StringJoiner(" "); for (String cmdArg : commandLine.toStrings()) { paramsJoiner.add(cmdArg.replaceAll("(?<=\\.password=)(.*)", "****")); } logger.info("Executing: " + paramsJoiner.toString()); return executor.execute(commandLine, env); } catch (ExecuteException e) { return e.getExitValue(); } catch (Exception e) { throw new MuleControllerException("Error executing [" + commandLine.getExecutable() + " " + commandLine.getArguments() + "]", e); } }
final String command = cmd.getExecutable(); if (cmd.isFile()) {// We assume it is it a script file out.print("$ @");
private static void logEndTime(CommandLine command, long startTime) { log.info("Completed " + command.getExecutable() + " in " + (System.currentTimeMillis() - startTime) + "ms"); }
private static Function<CommandLine, CommandLine> getLinuxShellWrapperFunc() { return (cmd) -> { final String originalCmd = Stream.concat( Arrays.stream(new String[]{cmd.getExecutable()}), Arrays.stream(cmd.getArguments()) ).collect(Collectors.joining(" ")); return new CommandLine("/bin/sh") .addArgument("-c") .addArgument(originalCmd, false); }; }
/** * Execute the sub-process * * @param executor * The executor to use * @param cmdLine * The command line to execute * @param streamHandler * The stream handler to use * @throws MojoExecutionException * If the process execution fails */ protected void executeTarget(Executor executor, CommandLine cmdLine, PumpStreamHandler streamHandler) throws MojoExecutionException { executor.setStreamHandler(streamHandler); try { executor.execute(cmdLine); } catch (IOException e) { getLog().error("Failed to run " + cmdLine.getExecutable(), e); throw new MojoExecutionException("Failed to run " + cmdLine.getExecutable(), e); } } }
mlcpCommand.add(commandLineAdditionalParams.getExecutable()); mlcpCommand.addAll(Arrays.asList(commandLineAdditionalParams.getArguments()));
mlcpCommand.add(commandLineAdditionalParams.getExecutable()); mlcpCommand.addAll(Arrays.asList(commandLineAdditionalParams.getArguments()));
private Protos.CommandInfo buildCommand(final Protos.CommandInfo.URI uri, final String script, final ShardingContexts shardingContexts, final boolean isCommandExecutor) { Protos.CommandInfo.Builder result = Protos.CommandInfo.newBuilder().addUris(uri).setShell(true); if (isCommandExecutor) { CommandLine commandLine = CommandLine.parse(script); commandLine.addArgument(GsonFactory.getGson().toJson(shardingContexts), false); result.setValue(Joiner.on(" ").join(commandLine.getExecutable(), Joiner.on(" ").join(commandLine.getArguments()))); } else { result.setValue(script); } return result.build(); }
public void launch(String argument, String[] params) throws ExecuteException, IOException, InterruptedException { CommandLine cmd = environment.getCommand(); cmd.addArgument(argument); cmd.addArguments(params); executor = new ScriptExecutor(); if (timeout != null) { executor.setTimeout(timeout); } Logger.debug("Setting executor working directory to " + project.getLocation().toOSString()); executor.setWorkingDirectory(project.getLocation().toFile()); for (ExecutionResponseListener listener : listeners) { executor.addResponseListener(listener); } Map<String, String> env = new HashMap<String, String>(System.getenv()); PHPLaunchUtilities.appendLibrarySearchPathEnv(env, new File(cmd.getExecutable()).getParentFile()); executor.execute(cmd, env); }
public void execute(CommandLine cmd, Map<String, String> env) { try { for (ExecutionResponseListener handler : listeners) { handler.executionAboutToStart(); } Logger.debug("executing command using executable: " + cmd.getExecutable()); executor.setExitValue(0); executor.execute(cmd, env, handler); for (ExecutionResponseListener handler : listeners) { handler.executionStarted(); } handler.waitFor(); } catch (Exception e) { for (ExecutionResponseListener handler : listeners) { handler.executionFailed("", e); } } }