/** * Open the resource by invoking the "open" command on the command line. */ @Override public int openResource(String resource) throws IOException { // bail out if nothing to open... if (resource != null) { // open works on file URI's too! :) ProcessLauncher launcher = new ProcessLauncher(new String[] { "open", resource }); int result = launcher.launch(); // show output from command if (launcher.getStandardOutput().length() > 0) { logger.info(launcher.getStandardOutput()); } if (launcher.getErrorOutput().length() > 0) { logger.warn(launcher.getErrorOutput()); } return result; } return -1; } }
public ProcessLauncher(ArrayList<?> commandList, File baseDir) { this(toStringArray(commandList), baseDir); }
/** * Check whether this is windows 9x, or windows NT and higher. */ public boolean isWin9x() { if (isWin9x == 0) { // let's see if this is windows 9x try { ProcessLauncher launcher = new ProcessLauncher(new String[] { "cmd", "/c", "echo" }); launcher.launch(); isWin9x = -1; } catch (ProcessLauncher.CommandNotExistsException nosuchcommand) { isWin9x = 1; } catch (Exception e) { logger.error("Unexpected exception while checking isWin9x", e); } } return isWin9x == 1; }
ProcessLauncher launcher = new ProcessLauncher(new String[] { "ls", "-l", netURI.getPath() }, null); launcher.launch(); String output = launcher.getStandardOutput();
package pkg2; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.List; import javax.swing.SwingWorker; public class SwingWorkerWrapper extends SwingWorker<Integer, Void> { private ProcessLauncher processLauncher; public SwingWorkerWrapper(List<String> commands) { processLauncher = new ProcessLauncher(commands); processLauncher.addPropertyChangeListener(new LauncherListener()); } @Override protected Integer doInBackground() throws Exception { return processLauncher.call(); } private class LauncherListener implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent evt) { firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); } } }
stderr.join(10000); if (exitValue != 0) { logger.info("WARNING: exit value " + exitValue + " for command \"" + getCommandLine() + "\""); logger.error("Exception while running/launching \"" + getCommandLine() + "\".", e);
/** * Check whether this is windows 9x, or windows NT and higher. */ public boolean isWin9x() { if (isWin9x == 0) { // let's see if this is windows 9x try { ProcessLauncher launcher = new ProcessLauncher(new String[] { "cmd", "/c", "echo" }); launcher.launch(); isWin9x = -1; } catch (ProcessLauncher.CommandNotExistsException nosuchcommand) { isWin9x = 1; } catch (Exception e) { logger.error("Unexpected exception while checking isWin9x", e); } } return isWin9x == 1; }
ProcessLauncher launcher = new ProcessLauncher(new String[] { "file", "-b", "-i", uri.getPath() }, null); if (launcher.launch() == 0) { if (launcher.getStandardOutput().trim().length() > 0) { String output = launcher.getStandardOutput().trim(); if (output.indexOf("\n") < 0 && output.indexOf("/") > 0) { int semiColonIndex = output.indexOf(";");
stderr.join(10000); if (exitValue != 0) { logger.info("WARNING: exit value " + exitValue + " for command \"" + getCommandLine() + "\""); logger.error("Exception while running/launching \"" + getCommandLine() + "\".", e);
/** * Opens applications by invoking 'kfmclient' that is part of KDE. */ @Override public int openWithDesktopEnvironment(String resource) throws UnsupportedOperationException, IOException { if (resource != null) { ProcessLauncher launcher = new ProcessLauncher(new String[] { "kfmclient", "exec", resource }, null); int exitValue = launcher.launch(); if (exitValue != 0) { logger.warn("Opening \"" + resource + "\" returned error code " + exitValue); } if (launcher.getStandardOutput().length() > 0) { logger.info(launcher.getStandardOutput()); } if (launcher.getErrorOutput().length() > 0) { logger.warn(launcher.getErrorOutput()); } return exitValue; } return -1; } }
ProcessLauncher launcher = new ProcessLauncher(command); return launcher.launch();
public ProcessLauncher(ArrayList<?> commandList, File baseDir) { this(toStringArray(commandList), baseDir); }
ProcessLauncher launcher = new ProcessLauncher(commandArray, null); int exitValue = launcher.launch(); String output = launcher.getStandardOutput(); if (output.length() > 0) { logger.info(output); output = launcher.getErrorOutput(); if (output.length() > 0) { logger.warn(output);
ProcessLauncher launcher = new ProcessLauncher(commandLine, null); int exitValue = launcher.launch(); String output = launcher.getStandardOutput(); if (output.length() > 0) { logger.info(output); output = launcher.getErrorOutput(); if (output.length() > 0) { logger.warn(output);