@Override public void run() { try { final ProcessResult result = ProcessResult.getProcessResult(process); int exitVal = result.getExitVal(); if(exitVal != 0) { logger.log(Level.SEVERE, "Non-zero exit status from \"{0}\": {1}", new Object[]{path, exitVal}); } String stdErr = result.getStderr(); if(!stdErr.isEmpty()) { logger.log(Level.SEVERE, "Standard error from \"{0}\":\n{1}", new Object[]{path, stdErr}); } if(logger.isLoggable(Level.INFO)) { String stdOut = result.getStdout(); if(!stdOut.isEmpty()) { logger.log(Level.INFO, "Standard output from \"{0}\":\n{1}", new Object[]{path, stdOut}); } } } catch(IOException e) { logger.log(Level.SEVERE, null, e); } } }
/** * Calls the <code>firewall-cmd</code> command with the given arguments * * @throws IOException when I/O exception or non-zero exit value */ private static ProcessResult execFirewallCmd(String ... args) throws IOException { String[] command = new String[1 + args.length]; command[0] = FIREWALL_CMD_EXE; System.arraycopy(args, 0, command, 1, args.length); ProcessResult result; synchronized(firewallCmdLock) { result = ProcessResult.exec(command); } if(result.getExitVal() != 0) throw new IOException(result.getStderr()); return result; }
ResourceSynchronizationResultStep step; try { ProcessResult processResult = ProcessResult.exec(command); step = new ResourceSynchronizationResultStep( startTime, System.currentTimeMillis(), processResult.getExitVal()==0 ? ResourceStatus.HEALTHY : ResourceStatus.ERROR, commandString, getList(processResult.getStdout()), null, getList(processResult.getStderr()) ); } catch(Exception exc) { ProcessResult processResult = ProcessResult.exec(command); int exitVal = processResult.getExitVal(); step = new ResourceSynchronizationResultStep( startTime, : ResourceStatus.ERROR, commandString, getList(processResult.getStdout()), exitVal==0 ? getList(processResult.getStderr()) : null, exitVal!=0 ? getList(processResult.getStderr()) : null ); } catch(Exception exc) {
ProcessResult result = execFirewallCmd("--permanent", "--list-all-zones"); Map<String,Set<String>> allServices = new LinkedHashMap<String,Set<String>>(); BufferedReader in = new BufferedReader(new StringReader(result.getStdout())); try { String currentZone = null;
/** * Gets the result of the provided process in the system default character set. */ public static ProcessResult getProcessResult(Process process) throws IOException { return getProcessResult(process, Charset.defaultCharset()); }
return new ProcessResult( exitVal, stdout,
/** * Executes the provided command and gets the result in the provided character set. */ public static ProcessResult exec(String[] command, Charset charset) throws IOException { return getProcessResult(Runtime.getRuntime().exec(command), charset); }
ProcessResult result = ProcessResult.getProcessResult(p); if(result.getExitVal() != 0) throw new IOException("Unable to find submodules: " + result.getStderr()); List<String> submodules = StringUtility.splitLines(result.getStdout()); if(DEBUG) { for(String submodule : submodules) log("Got submodule: " + submodule); ProcessResult result = ProcessResult.getProcessResult(p); if(result.getExitVal() != 0) throw new IOException("Unable to get status: " + result.getStderr()); List<String> split = new ArrayList<>(StringUtility.splitString(result.getStdout(), (char)0)); if(!split.isEmpty()) {
ProcessResult result = ProcessResult.exec(command); int exitVal = result.getExitVal(); if(exitVal != 0) throw new IOException(diaExePath + ": non-zero exit value: " + exitVal); if(!isWindows()) { String stderr = result.getStderr(); BufferedReader errIn = new BufferedReader(new StringReader(stderr)); try {
/** * Executes the provided command and gets the result in the system default character set. */ public static ProcessResult exec(String ... command) throws IOException { return getProcessResult(Runtime.getRuntime().exec(command), Charset.defaultCharset()); }