use of org.apache.commons.exec.DefaultExecutor in project x-pipe by ctripcorp.
the class AbstractRedisTest method executeScript.
protected void executeScript(String file, String... args) throws ExecuteException, IOException {
URL url = getClass().getClassLoader().getResource(file);
if (url == null) {
url = getClass().getClassLoader().getResource("scripts/" + file);
if (url == null) {
throw new FileNotFoundException(file);
}
}
DefaultExecutor executor = new DefaultExecutor();
String command = "sh -v " + url.getFile() + " " + StringUtil.join(" ", args);
executor.execute(CommandLine.parse(command));
}
use of org.apache.commons.exec.DefaultExecutor in project x-pipe by ctripcorp.
the class AbstractRedisTest method executeCommands.
protected void executeCommands(String... args) throws ExecuteException, IOException {
DefaultExecutor executor = new DefaultExecutor();
executor.execute(CommandLine.parse(StringUtil.join(" ", args)));
}
use of org.apache.commons.exec.DefaultExecutor in project vespa by vespa-engine.
the class ProcessExecutor method execute.
/**
* Executes the given command synchronously.
*
* @param command The command to execute.
* @param processInput Input provided to the process.
* @return The result of the execution, or empty if the process does not terminate within the timeout set for this executor.
* @throws IOException if the process execution failed.
*/
public Optional<ProcessResult> execute(String command, String processInput) throws IOException {
ByteArrayOutputStream processErr = new ByteArrayOutputStream();
ByteArrayOutputStream processOut = new ByteArrayOutputStream();
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(createStreamHandler(processOut, processErr, processInput));
ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.SECONDS.toMillis(timeoutSeconds));
executor.setWatchdog(watchDog);
executor.setExitValues(successExitCodes);
int exitCode;
try {
exitCode = executor.execute(CommandLine.parse(command));
} catch (ExecuteException e) {
exitCode = e.getExitValue();
}
return (watchDog.killedProcess()) ? Optional.empty() : Optional.of(new ProcessResult(exitCode, processOut.toString(), processErr.toString()));
}
use of org.apache.commons.exec.DefaultExecutor in project fql by CategoricalData.
the class ProcPragma method execute.
@Override
public void execute() {
try {
for (String cmd : cmds) {
// CommandLine.
CommandLine cmdLine = CommandLine.parse(cmd);
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new ProcHandler(cmd));
executor.execute(cmdLine);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.commons.exec.DefaultExecutor in project jackrabbit-oak by apache.
the class HybridIndexTest method dumpOpenFilePaths.
private static void dumpOpenFilePaths() throws IOException {
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
String pid = jvmName.split("@")[0];
CommandLine cl = new CommandLine("/bin/sh");
cl.addArguments(new String[] { "-c", "lsof -p " + pid + " | grep '/nrt'" }, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(baos));
executor.execute(cl);
System.out.println(new String(baos.toByteArray()));
}
Aggregations