List of usage examples for java.lang Process getErrorStream
public abstract InputStream getErrorStream();
From source file:arena.fileupload.transform.ExternalProcessFileTransform.java
public void transform(File in, File out) throws IOException { String[] resizeCmdArgs = buildParsedCommandLine(in, out); if (System.getProperty("os.name", "").toUpperCase().startsWith("WINDOWS")) { String winPrefix[] = new String[resizeCmdArgs.length + 2]; winPrefix[0] = "cmd.exe"; winPrefix[1] = "/C"; System.arraycopy(resizeCmdArgs, 0, winPrefix, 2, resizeCmdArgs.length); resizeCmdArgs = winPrefix;// w ww . j a v a 2 s. co m } log.debug("Launching external process: " + Arrays.asList(resizeCmdArgs)); //comment out Process p = Runtime.getRuntime().exec(resizeCmdArgs); Thread thStdOut = new Thread(new LoggingStreamConsumer(p.getInputStream(), logEncoding)); Thread thStdErr = new Thread(new LoggingStreamConsumer(p.getErrorStream(), logEncoding)); thStdOut.setDaemon(true); thStdOut.start(); thStdErr.setDaemon(true); thStdErr.start(); try { int result = p.waitFor(); log.info(getClass().getName() + " process completed with exit code " + result); } catch (InterruptedException err) { log.error("Timeout waiting for " + getClass().getName() + " process", err); } }
From source file:com.alibaba.jstorm.yarn.utils.JStormUtils.java
public static String launchProcess(final String command, final List<String> cmdlist, final Map<String, String> environment, boolean backend) throws IOException { if (backend) { new Thread(new Runnable() { @Override/*from w w w .j a v a2 s . c om*/ public void run() { List<String> cmdWrapper = new ArrayList<String>(); cmdWrapper.add("nohup"); cmdWrapper.addAll(cmdlist); cmdWrapper.add("&"); try { launchProcess(cmdWrapper, environment); } catch (IOException e) { LOG.error("Failed to run nohup " + command + " &," + e.getCause(), e); } } }).start(); return null; } else { try { Process process = launchProcess(cmdlist, environment); StringBuilder sb = new StringBuilder(); String output = JStormUtils.getOutput(process.getInputStream()); String errorOutput = JStormUtils.getOutput(process.getErrorStream()); sb.append(output); sb.append("\n"); sb.append(errorOutput); int ret = process.waitFor(); if (ret != 0) { LOG.warn(command + " is terminated abnormally. ret={}, str={}", ret, sb.toString()); } return sb.toString(); } catch (Throwable e) { LOG.error("Failed to run " + command + ", " + e.getCause(), e); } return ""; } }
From source file:com.photon.phresco.impl.AndroidDevicesParameterImpl.java
public PossibleValues getValues(Map<String, Object> map) throws IOException, ParserConfigurationException, SAXException, ConfigurationException, PhrescoException { ArrayList<String> devices = new ArrayList<String>(); try {//from w w w . j av a 2 s. co m String s = null; Process p = Runtime.getRuntime().exec(CMD_ADB_DEVICES); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); int cnt = 0; while ((s = stdInput.readLine()) != null) { if (cnt > 0) { s = s.substring(0, s.indexOf("\t") + 1); devices.add(s.trim()); } cnt++; } stdInput.close(); cnt = 0; while ((s = stdError.readLine()) != null) { if (cnt > 0) { s = s.substring(0, s.indexOf("\t") + 1); devices.add(s.trim()); } cnt++; } stdError.close(); } catch (Exception e) { // Error in retriving connected devices } PossibleValues possibleValues = new PossibleValues(); if (CollectionUtils.isNotEmpty(devices)) { devices.remove(devices.size() - 1); for (String device : devices) { Value value = new Value(); value.setValue(device); possibleValues.getValue().add(value); } } return possibleValues; }
From source file:com.thoughtworks.gauge.maven.GaugeExecutionMojo.java
private void executeGaugeSpecs() throws GaugeExecutionFailedException { try {//w w w . j a v a 2 s . c om ProcessBuilder builder = createProcessBuilder(); debug("Executing => " + builder.command()); Process process = builder.start(); Util.InheritIO(process.getInputStream(), System.out); Util.InheritIO(process.getErrorStream(), System.err); if (process.waitFor() != 0) { throw new GaugeExecutionFailedException(); } } catch (InterruptedException e) { throw new GaugeExecutionFailedException(e); } catch (IOException e) { throw new GaugeExecutionFailedException(e); } }
From source file:de.uni_freiburg.informatik.ultimate.licence_manager.authors.SvnAuthorProvider.java
private InputStream getSvnBlameProcess(String absolutePath) throws IOException, InterruptedException { final Process process = new ProcessBuilder("svn", "blame", "--xml", absolutePath).start(); ProcessUtils.inheritIO(process.getErrorStream(), System.err); StreamGobbler gobbler = ProcessUtils.attachGobbler(process.getInputStream()); while (!process.waitFor(2500, TimeUnit.MILLISECONDS)) { System.out.print("."); }/*w w w .j av a 2 s . c o m*/ return gobbler.getFreshStream(); }
From source file:io.wcm.maven.plugins.nodejs.mojo.Task.java
private void initLogging(final Process process) throws InterruptedException { final Thread infoLogThread = new NodejsOutputStreamHandler(process.getInputStream(), getLog()); final Thread errorLogThread = new NodejsOutputStreamHandler(process.getErrorStream(), getLog()); infoLogThread.start();/*from w ww .j a va 2 s . c om*/ errorLogThread.start(); infoLogThread.join(); errorLogThread.join(); }
From source file:com.laex.cg2d.screeneditor.handlers.RenderHandler.java
/** * the command has been executed, so extract extract the needed information * from the application context./* www. ja v a2 s . co m*/ * * @param event * the event * @return the object * @throws ExecutionException * the execution exception */ public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); final IEditorPart editorPart = window.getActivePage().getActiveEditor(); editorPart.doSave(new NullProgressMonitor()); validate(window.getShell()); // Eclipse Jobs API final Job job = new Job("Render Game") { @Override protected IStatus run(IProgressMonitor monitor) { if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } try { IFile file = ((IFileEditorInput) editorPart.getEditorInput()).getFile(); monitor.beginTask("Building rendering command", 5); ILog log = Activator.getDefault().getLog(); String mapFile = file.getLocation().makeAbsolute().toOSString(); String controllerFile = file.getLocation().removeFileExtension().addFileExtension("lua") .makeAbsolute().toOSString(); String[] command = buildRunnerCommandFromProperties(mapFile, controllerFile); monitor.worked(5); monitor.beginTask("Rendering external", 5); ProcessBuilder pb = new ProcessBuilder(command); Process p = pb.start(); monitor.worked(4); Scanner scn = new Scanner(p.getErrorStream()); while (scn.hasNext() && !monitor.isCanceled()) { if (monitor.isCanceled()) { throw new InterruptedException("Cancelled"); } log.log(new Status(IStatus.INFO, Activator.PLUGIN_ID, scn.nextLine())); } monitor.worked(5); monitor.done(); this.done(Status.OK_STATUS); return Status.OK_STATUS; } catch (RuntimeException e) { return handleException(e); } catch (IOException e) { return handleException(e); } catch (CoreException e) { return handleException(e); } catch (InterruptedException e) { return handleException(e); } } private IStatus handleException(Exception e) { Activator.log(e); return Status.CANCEL_STATUS; } }; job.setUser(true); job.setPriority(Job.INTERACTIVE); job.schedule(); return null; }
From source file:jetbrains.exodus.util.ForkSupportIO.java
public ForkSupportIO start() throws IOException, InterruptedException { if (process == null) { if (log.isInfoEnabled()) { log.info("starting child process [" + name + ']'); log.info("============================================"); }//w w w .ja v a2 s.c om final Process spawned = spawnProcess(); err = createSpinner(spawned.getErrorStream(), System.err, BUFFER_SIZE, "IO [err] " + name); out = createSpinner(spawned.getInputStream(), System.out, BUFFER_SIZE, "IO [out] " + name); process = spawned; return this; } else { throw new IllegalStateException("Process already started"); } }
From source file:org.apache.cxf.cwiki.SiteExporter.java
static void callSvn(File dir, String... commands) throws Exception { if (svn) {//from ww w . j ava2s.co m List<String> cmds = new ArrayList<String>(); cmds.add("svn"); cmds.add("--non-interactive"); cmds.addAll(Arrays.asList(commands)); Process p = Runtime.getRuntime().exec(cmds.toArray(new String[cmds.size()]), new String[0], dir); if (p.waitFor() != 0) { IOUtils.copy(p.getErrorStream(), System.err); } } }
From source file:com.google.gwt.benchmark.compileserver.server.manager.CliInteractor.java
private String runCommand(String command, boolean useErrorSteam) throws BenchmarkManagerException { InputStream stream = null;/*from www . j a v a 2 s . c o m*/ try { Process process = Runtime.getRuntime().exec(command); int exitValue = process.waitFor(); if (exitValue != 0) { stream = useErrorSteam ? process.getErrorStream() : process.getInputStream(); String error = "Command returned with " + exitValue + " " + IOUtils.toString(stream, "UTF-8"); logger.warning(error); throw new BenchmarkManagerException(error); } stream = process.getInputStream(); return IOUtils.toString(stream, "UTF-8"); } catch (IOException | InterruptedException e) { logger.log(Level.WARNING, "Can not run command", e); throw new BenchmarkManagerException("Can not run command"); } finally { IOUtils.closeQuietly(stream); } }