use of org.apache.commons.exec.Executor in project zeppelin by apache.
the class MongoDbInterpreter method stopProcess.
private void stopProcess(String paragraphId) {
if (runningProcesses.containsKey(paragraphId)) {
final Executor executor = runningProcesses.get(paragraphId);
final ExecuteWatchdog watchdog = executor.getWatchdog();
watchdog.destroyProcess();
runningProcesses.remove(paragraphId);
}
}
use of org.apache.commons.exec.Executor in project Robot by fo0.
the class Commander method execute.
public String execute(boolean wait, boolean shell, String homedir, boolean quoting, List<String> cmds) {
if (cmds == null || cmds.isEmpty()) {
Logger.info("stopped cmd command is empty");
return null;
}
CommandLine cmdLine = null;
if (shell) {
switch(OSCheck.getOperatingSystemType()) {
case Windows:
cmdLine = new CommandLine("cmd");
if (shell) {
cmdLine.addArgument("/c");
}
break;
case Linux:
cmdLine = new CommandLine("/bin/bash");
if (shell) {
cmdLine.addArgument("-c");
}
break;
}
cmdLine.addArguments(cmds.stream().toArray(String[]::new), quoting);
} else {
cmdLine = new CommandLine(cmds.get(0));
cmdLine.addArguments(cmds.stream().skip(1).toArray(String[]::new), quoting);
}
Logger.debug("HomeDir: '" + Paths.get(homedir).toAbsolutePath() + "' => " + cmdLine.getExecutable() + ", " + StringUtils.join(cmdLine.getArguments(), ","));
try {
Executor executor = createDefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(new OutputStream() {
@Override
public void write(int b) throws IOException {
try {
String str = String.valueOf((char) b);
if (listener != null)
listener.event(str);
buffer.append(str);
} catch (Exception e) {
Logger.debug(e.getMessage());
}
}
}, new OutputStream() {
@Override
public void write(int b) throws IOException {
error = true;
try {
String str = String.valueOf((char) b);
if (listener != null)
listener.event(str);
buffer.append(str);
} catch (Exception e) {
Logger.debug(e.getMessage());
}
}
}));
// configure timeout
// executor.setWatchdog(new ExecuteWatchdog(-1));
executor.setWorkingDirectory(new File(homedir));
if (wait) {
executor.execute(cmdLine);
} else {
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
executor.execute(cmdLine, resultHandler);
}
} catch (Exception e) {
error = true;
Logger.error("failed commander in Cmd: " + cmdLine + " | " + e);
Logger.debug(e.getMessage());
}
return buffer.toString();
}
Aggregations