executor.setWorkingDirectory(new File(workDir));
executor.setWorkingDirectory(new File(workDir));
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; }
public void setWorkingDirectory(File dir) { executor.setWorkingDirectory(dir); }
public static DefaultExecutor createExecutor(File distFolder) { DefaultExecutor oDefaultExecutor = new DefaultExecutor(); oDefaultExecutor.setWorkingDirectory(distFolder); return oDefaultExecutor; }
File file = new File("C:\\Users\\Aaron\\Documents\\MinecraftForge\\forge\\mcp"); for(File s : file.listFiles()) { if(s.getName().equals("recompile.bat")) { DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(file); CommandLine commandLine = new CommandLine(s.getAbsolutePath()); try { executor.execute(commandLine); } catch (ExecuteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
public static String runCommand(String command, Optional<File> dir) throws IOException { String[] commands = command.split("\\|"); ByteArrayOutputStream output = null; for (String cmd : commands) { output = runSubCommand(output != null ? new ByteArrayInputStream(output.toByteArray()) : null, cmd.trim(), dir); } return output != null ? output.toString() : null; } private static ByteArrayOutputStream runSubCommand(ByteArrayInputStream input, String command, Optional<File> dir) throws IOException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); CommandLine cmd = CommandLine.parse(command); DefaultExecutor exec = new DefaultExecutor(); if (dir.isPresent()) { exec.setWorkingDirectory(dir.get()); } PumpStreamHandler streamHandler = new PumpStreamHandler(output, output, input); exec.setStreamHandler(streamHandler); exec.execute(cmd); return output; }
@Override public void execLMH(File cwd, String[] command, ExecuteStreamHandler outputHandlers) { DefaultExecutor executor = new DefaultExecutor(); CommandLine cmd = new CommandLine(lmhExecutable); cmd.addArguments(command); HashMap<String, String> env = new HashMap<String, String>(System.getenv()); env.put("GIT_SSH", lmhRootFile.getAbsolutePath()+"/bin/myssh"); if (outputHandlers != null) { executor.setStreamHandler(outputHandlers); } try { executor.setWorkingDirectory(cwd); executor.execute(cmd, env); } catch (IOException e) { log.error("LMH execution failed on "+cmd.toString(), e); e.printStackTrace(); } }
CommandLine cmdLine = CommandLine.parse(command); for (String comm : cmd) { cmdLine.addArgument(comm); } DefaultExecutor exec = new DefaultExecutor(); exec.setExitValue(0); exec.setWorkingDirectory(new File(codeDir)); exitCode = exec.execute(cmdLine);
void executeCommand(String command) throws MojoExecutionException { try { if (isWindows()) { command = "cmd /c " + command; } CommandLine cmdLine = CommandLine.parse(command); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(yeomanProjectDirectory); executor.execute(cmdLine); } catch (IOException e) { throw new MojoExecutionException("Error during : " + command, e); } }
private static DefaultExecutor getDefaultExecutor(File dir, int expectedExit, long timeout) { DefaultExecutor executor = new DefaultExecutor(); if(expectedExit != -1) { executor.setExitValue(expectedExit); } else { executor.setExitValues(null); } ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); executor.setWorkingDirectory(dir); return executor; }
executor.setStreamHandler(new PumpStreamHandler(os)); if (mWorkingDir.isPresent()) { executor.setWorkingDirectory(new File(mWorkingDir.get()));
protected DefaultExecutor prepareDefaultExecutor(ExecCommand execCommand) { DefaultExecutor executor = new ExecDefaultExecutor(); executor.setExitValues(null); if (execCommand.getWorkingDir() != null) { executor.setWorkingDirectory(new File(execCommand.getWorkingDir()).getAbsoluteFile()); } if (execCommand.getTimeout() != ExecEndpoint.NO_TIMEOUT) { executor.setWatchdog(new ExecuteWatchdog(execCommand.getTimeout())); } executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); return executor; }
public static void createSymbolicLink(Path link, Path target) throws IOException { if (!SystemUtils.IS_OS_WINDOWS) { Files.createSymbolicLink(link, target); } else { // In Windows, users need special privileges to create symlinks. But there are less general symlinks that // only work within one volume (which is fine for our purpose) called junctions (for directories). // Creating directory junctions works without additional privileges. Unfortunately, the current implementation // of Files.createSymbolicLink() under Windows uses symlinks. // Thus, for windows, we always use mklink to create directory junctions (/J) in favor of symlinks (/D). // fall back to command line execution: DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(link.toFile().getParentFile()); // prevent command line tool output from appearing in Maven log: executor.setStreamHandler(new PumpStreamHandler(null)); CommandLine mkLinkCommand = new CommandLine("CMD"); mkLinkCommand.addArgument("/C"); mkLinkCommand.addArgument("MKLINK"); mkLinkCommand.addArgument("/J"); mkLinkCommand.addArgument(link.getFileName().toString()); mkLinkCommand.addArgument(target.toString()); try { executor.execute(mkLinkCommand); } catch (IOException e) { throw new IOException("Error while invoking " + mkLinkCommand.toString(), e); } } }
executor.setWorkingDirectory(node.getWorkDir()); log.info("Executing " + cmdLine.toString() + " from " + executor.getWorkingDirectory().getAbsolutePath());
executor.setStreamHandler(streamHandler); if (baseDir != null) { executor.setWorkingDirectory(baseDir);
/** * Executes the command. * * @return Exit code. */ public final int execute() { try { final Map<String, String> envMap = EnvironmentUtils .getProcEnvironment(); envMap.put("DEBIAN_FRONTEND", "noninteractive"); envMap.putAll(env); final CommandLine command = new CommandLine("/bin/sh"); final String cmdStr = createSubCmd(); command.addArguments(new String[] { "-c", cmdStr }, false); final DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(out, err)); executor.setWorkingDirectory(workingDir); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); executor.setWatchdog(new ExecuteWatchdog(timeoutSeconds * 1000)); return executor.execute(command, envMap); } catch (final IOException ex) { throw new RuntimeException(ex); } }
EXECUTOR.setWorkingDirectory(cmd.getWorkingFile().getParentFile().getAbsoluteFile());
private DefaultExecuteResultHandler executeCommand(String commandLine) throws Exception { // The command line to execute CommandLine command = CommandLine.parse(commandLine); // Execute the process asynchronously so that we don't block. DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); // Send Process output and error streams to our logger. PumpStreamHandler streamHandler = new PumpStreamHandler( new XWikiLogOutputStream(XWikiLogOutputStream.STDOUT), new XWikiLogOutputStream(XWikiLogOutputStream.STDERR)); // Make sure we end the process when the JVM exits ShutdownHookProcessDestroyer processDestroyer = new ShutdownHookProcessDestroyer(); // Prevent the process from running indefinitely and kill it after 1 hour... ExecuteWatchdog watchDog = new ExecuteWatchdog(60L * 60L * 1000L); // The executor to execute the command DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(streamHandler); executor.setWorkingDirectory(new File(getExecutionDirectory())); executor.setProcessDestroyer(processDestroyer); executor.setWatchdog(watchDog); // Inherit the current process's environment variables and add the user-defined ones @SuppressWarnings("unchecked") Map<String, String> newEnvironment = EnvironmentUtils.getProcEnvironment(); newEnvironment.putAll(this.environment); executor.execute(command, newEnvironment, resultHandler); return resultHandler; }
executor.setWorkingDirectory(configuration.getWorkingDirectory()); try { return executor.execute(cli, getMergedEnvironment(configuration));