use of org.apache.commons.exec.ExecuteException in project robovm by robovm.
the class ToolchainUtil method findXcodePath.
public static String findXcodePath() throws IOException {
try {
String path = new Executor(Logger.NULL_LOGGER, "xcode-select").args("--print-path").execCapture();
File f = new File(path);
if (f.exists() && f.isDirectory()) {
if (new File(f, "Platforms").exists() && new File(f, "Toolchains").exists()) {
return path;
}
}
throw new IllegalArgumentException(String.format("The path '%s' does not appear to be a valid Xcode path. Use " + "'sudo xcode-select -switch <path-to-xcode>' from a Terminal " + "to switch to the correct Xcode path.", path));
} catch (ExecuteException e) {
handleExecuteException(e);
return null;
}
}
use of org.apache.commons.exec.ExecuteException in project hive by apache.
the class HcatDelegator method descExtendedTable.
/**
* Return a json "show table extended like" with extra info from "desc exteded"
* This will return table with exact name match.
*/
public Response descExtendedTable(String user, String db, String table) throws HcatException, NotAuthorizedException, BusyException, ExecuteException, IOException {
String exec = String.format("use %s; show table extended like %s;", db, table);
try {
//get detailed "tableInfo" from query "desc extended tablename;"
Response res0 = descTable(user, db, table, true);
if (res0.getStatus() != HttpStatus.OK_200)
return res0;
Map m = (Map) res0.getEntity();
Map tableInfo = (Map) m.get("tableInfo");
String res = jsonRun(user, exec);
JsonBuilder jb = JsonBuilder.create(singleTable(res, table)).remove("tableName").put("database", db).put("table", table).put("retention", tableInfo.get("retention")).put("sd", tableInfo.get("sd")).put("parameters", tableInfo.get("parameters")).put("parametersSize", tableInfo.get("parametersSize")).put("tableType", tableInfo.get("tableType"));
// If we can get them from HDFS, add group and permission
String loc = (String) jb.getMap().get("location");
if (loc != null && loc.startsWith("hdfs://")) {
try {
FileSystem fs = FileSystem.get(appConf);
FileStatus status = fs.getFileStatus(new Path(new URI(loc)));
jb.put("group", status.getGroup());
jb.put("permission", status.getPermission().toString());
} catch (Exception e) {
LOG.warn(e.getMessage() + " Couldn't get permissions for " + loc);
}
}
return jb.build();
} catch (HcatException e) {
throw new HcatException("unable to show table: " + table, e.execBean, exec);
}
}
use of org.apache.commons.exec.ExecuteException in project frontend-maven-plugin by eirslett.
the class ProcessExecutor method execute.
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);
}
}
use of org.apache.commons.exec.ExecuteException in project openhab1-addons by openhab.
the class ExecBinding method executeCommandAndWaitResponse.
/**
* <p>
* Executes <code>commandLine</code>. Sometimes (especially observed on
* MacOS) the commandLine isn't executed properly. In that cases another
* exec-method is to be used. To accomplish this please use the special
* delimiter '<code>@@</code>'. If <code>commandLine</code> contains this
* delimiter it is split into a String[] array and the special exec-method
* is used.
* </p>
* <p>
* A possible {@link IOException} gets logged but no further processing is
* done.
* </p>
*
* @param commandLine the command line to execute
* @return response data from executed command line
*/
private String executeCommandAndWaitResponse(String commandLine) {
String retval = null;
CommandLine cmdLine = null;
if (commandLine.contains(CMD_LINE_DELIMITER)) {
String[] cmdArray = commandLine.split(CMD_LINE_DELIMITER);
cmdLine = new CommandLine(cmdArray[0]);
for (int i = 1; i < cmdArray.length; i++) {
cmdLine.addArgument(cmdArray[i], false);
}
} else {
cmdLine = CommandLine.parse(commandLine);
}
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
Executor executor = new DefaultExecutor();
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(stdout);
executor.setExitValue(1);
executor.setStreamHandler(streamHandler);
executor.setWatchdog(watchdog);
try {
executor.execute(cmdLine, resultHandler);
logger.debug("executed commandLine '{}'", commandLine);
} catch (ExecuteException e) {
logger.error("couldn't execute commandLine '" + commandLine + "'", e);
} catch (IOException e) {
logger.error("couldn't execute commandLine '" + commandLine + "'", e);
}
// can safely request the exit code
try {
resultHandler.waitFor();
int exitCode = resultHandler.getExitValue();
retval = StringUtils.chomp(stdout.toString());
logger.debug("exit code '{}', result '{}'", exitCode, retval);
} catch (InterruptedException e) {
logger.error("Timeout occured when executing commandLine '" + commandLine + "'", e);
}
return retval;
}
use of org.apache.commons.exec.ExecuteException in project camel by apache.
the class DefaultExecCommandExecutor method execute.
@Override
public ExecResult execute(ExecCommand command) {
notNull(command, "command");
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
DefaultExecutor executor = prepareDefaultExecutor(command);
// handle error and output of the process and write them to the given
// out stream
PumpStreamHandler handler = new PumpStreamHandler(out, err, command.getInput());
executor.setStreamHandler(handler);
CommandLine cl = toCommandLine(command);
try {
int exitValue = executor.execute(cl);
// if the size is zero, we have no output, so construct the result
// with null (required by ExecResult)
InputStream stdout = out.size() == 0 ? null : new ByteArrayInputStream(out.toByteArray());
InputStream stderr = err.size() == 0 ? null : new ByteArrayInputStream(err.toByteArray());
ExecResult result = new ExecResult(command, stdout, stderr, exitValue);
return result;
} catch (ExecuteException ee) {
LOG.error("ExecException while executing command: " + command.toString() + " - " + ee.getMessage());
InputStream stdout = out.size() == 0 ? null : new ByteArrayInputStream(out.toByteArray());
InputStream stderr = err.size() == 0 ? null : new ByteArrayInputStream(err.toByteArray());
throw new ExecException("Failed to execute command " + command, stdout, stderr, ee.getExitValue(), ee);
} catch (IOException ioe) {
InputStream stdout = out.size() == 0 ? null : new ByteArrayInputStream(out.toByteArray());
InputStream stderr = err.size() == 0 ? null : new ByteArrayInputStream(err.toByteArray());
// use 0 as exit value as the executor didn't return the value
int exitValue = 0;
if (executor instanceof ExecDefaultExecutor) {
// get the exit value from the executor as it captures this to work around the common-exec bug
exitValue = ((ExecDefaultExecutor) executor).getExitValue();
}
// workaround to ignore if the stream was already closes due some race condition in commons-exec
String msg = ioe.getMessage();
if (msg != null && "stream closed".equals(msg.toLowerCase(Locale.ENGLISH))) {
LOG.debug("Ignoring Stream closed IOException", ioe);
ExecResult result = new ExecResult(command, stdout, stderr, exitValue);
return result;
}
// invalid working dir
LOG.error("IOException while executing command: " + command.toString() + " - " + ioe.getMessage());
throw new ExecException("Unable to execute command " + command, stdout, stderr, exitValue, ioe);
} finally {
// the inputStream must be closed after the execution
IOUtils.closeQuietly(command.getInput());
}
}
Aggregations