List of usage examples for java.lang Process getOutputStream
public abstract OutputStream getOutputStream();
From source file:org.panbox.desktop.common.vfs.backend.dropbox.DropboxClientIntegration.java
@Override public boolean isClientRunning() { if (OS.getOperatingSystem().isLinux()) { try {//from w ww.jav a 2s . c om String pid = FileUtils .readFileToString(new File(getClientConfigDir(), DropboxConstants.LINUX_PID_FILE)); if (pid != null) { pid = pid.trim(); } String ret = FileUtils.readFileToString( new File(File.separator + "proc" + File.separator + pid + File.separator + "cmdline")); return ret.contains("dropbox"); } catch (IOException e) { return false; } } else if (OS.getOperatingSystem().isWindows()) { try { ProcessBuilder pb = new ProcessBuilder("wmic", "process", "list"); pb.redirectErrorStream(true); Process p = pb.start(); p.getOutputStream().close(); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String tmp = null; while ((tmp = br.readLine()) != null) { // System.out.println(tmp); if (tmp.toLowerCase().contains("dropbox.exe")) { return true; } } p.waitFor(); } catch (IOException | InterruptedException e) { logger.error("Failed to execute check for running Dropbox.exe: ", e); } return false; } return true; }
From source file:org.tariel.dependrpc.pos.JMystem.java
public ISentence parseSentence(String sentence) { String readyJson = new String(); try {/*w w w. ja v a 2s. c om*/ Process process = new ProcessBuilder(this.executable, "-i", "--format=json").start(); InputStream is = process.getInputStream(); OutputStream os = process.getOutputStream(); InputStreamReader isr = new InputStreamReader(is, "UTF-8"); OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8"); BufferedWriter bw = new BufferedWriter(osw); BufferedReader br = new BufferedReader(isr); bw.write(sentence); bw.close(); String line = new String(); while ((line = br.readLine()) != null) { if (!line.isEmpty()) { readyJson = line; } } } catch (IOException ex) { ex.printStackTrace(); } List<JsonWord> sent = this.processJsonOutput(readyJson); return this.createSentence(sent); }
From source file:nl.bneijt.javapjson.JavapJsonMojo.java
private String runJavap(File classFile) throws MojoExecutionException { File classDirectory = classFile.getParentFile(); String classFileName = classFile.getName(); ProcessBuilder psBuilder = new ProcessBuilder("javap", "-l", classFileName.substring(0, classFileName.length() - CLASS_EXTENSION.length())); psBuilder.directory(classDirectory); Process process; try {//from w w w .j a v a 2 s . c o m process = psBuilder.start(); } catch (IOException e1) { throw new MojoExecutionException("Could not start process builder", e1); } try { process.getOutputStream().close(); } catch (IOException e) { throw new MojoExecutionException("Could not close output stream while executing javap"); } try { byte[] buffer = new byte[1024]; IOUtils.read(process.getInputStream(), buffer); return new String(buffer); } catch (IOException e) { throw new MojoExecutionException( "Could not read all input from command javap while reading \"" + classFile + "\""); } }
From source file:com.mdsh.test.media.encoding.process.AbstractProcess.java
protected synchronized void closeProcess() { final Process process = getProcess(); if (null != process) { IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getOutputStream()); IOUtils.closeQuietly(process.getErrorStream()); }//from ww w .j a v a2 s .c o m }
From source file:VASSAL.tools.io.ProcessLauncher.java
/** * Launches a process.//from w ww. jav a 2 s. com * * @param workDir the process' working directory * @param stdout the stream where the process' STDOUT is redirected * @param stderr the stream where the process' STDERR is redirected * @param args the command-line arguments * * @throws IOException if the process fails to launch */ public ProcessWrapper launch(File workDir, InputStreamPump stdoutPump, InputStreamPump stderrPump, String... args) throws IOException { logger.info("launching " + StringUtils.join(args, ' ')); final ProcessBuilder pb = new ProcessBuilder(args); pb.directory(workDir); final Process proc = pb.start(); final ProcessCallable pcall = new ProcessCallable(proc, stdoutPump, stderrPump, exec); final Future<Integer> future = exec.submit(pcall); return new ProcessWrapper(future, proc.getInputStream(), proc.getErrorStream(), proc.getOutputStream()); }
From source file:uk.ac.kcl.tika.parsers.TesseractOCRParser.java
/** * Run external tesseract-ocr process./*from w ww . ja v a2s .com*/ * * @param input * File to be ocred * @param output * File to collect ocr result * @param config * Configuration of tesseract-ocr engine * @throws TikaException * if the extraction timed out * @throws IOException * if an input error occurred */ private void doOCR(File input, File output, TesseractOCRConfig config) throws IOException, TikaException { String[] cmd = { config.getTesseractPath() + getTesseractProg(), input.getPath(), output.getPath(), "-l", config.getLanguage(), "-psm", config.getPageSegMode() }; ProcessBuilder pb = new ProcessBuilder(cmd); setEnv(config, pb); final Process process = pb.start(); process.getOutputStream().close(); InputStream out = process.getInputStream(); InputStream err = process.getErrorStream(); logStream("OCR MSG", out, input); logStream("OCR ERROR", err, input); FutureTask<Integer> waitTask = new FutureTask<Integer>(new Callable<Integer>() { public Integer call() throws Exception { return process.waitFor(); } }); Thread waitThread = new Thread(waitTask); waitThread.start(); try { waitTask.get(config.getTimeout(), TimeUnit.SECONDS); } catch (InterruptedException e) { waitThread.interrupt(); process.destroy(); Thread.currentThread().interrupt(); throw new TikaException("TesseractOCRParser interrupted", e); } catch (ExecutionException e) { // should not be thrown } catch (TimeoutException e) { waitThread.interrupt(); process.destroy(); throw new TikaException("TesseractOCRParser timeout", e); } }
From source file:de.cosmocode.palava.store.FileSystemStore.java
private void close(Process process) { Closeables.closeQuietly(process.getInputStream()); Closeables.closeQuietly(process.getOutputStream()); Closeables.closeQuietly(process.getErrorStream()); }
From source file:com.pinterest.deployservice.scm.PhabricatorManager.java
private Map<String, Object> queryCLI(String input) throws Exception { ProcessBuilder builder;//from www. j a v a2 s .c o m if (StringUtils.isEmpty(arcrcLocation)) { builder = new ProcessBuilder(arcLocation, "call-conduit", String.format("--conduit-uri=%s", urlPrefix), "diffusion.historyquery"); } else { builder = new ProcessBuilder(arcLocation, "call-conduit", String.format("--conduit-uri=%s", urlPrefix), "diffusion.historyquery", "--arcrc-file", arcrcLocation); } LOG.debug("Execute arc command: \n{}", builder.command()); // Redirects error stream to output stream, so have only one input stream to read from builder.redirectErrorStream(true); // Run command Process process = builder.start(); // Feed the input parameters BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); writer.write(input); writer.flush(); writer.close(); InputStream stdout = process.getInputStream(); String line; StringBuilder sb = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(stdout)); // Read response while ((line = reader.readLine()) != null) { sb.append(line); } reader.close(); // We will remove "Waiting for JSON parameters on stdin..." from the output if exists String output = sb.toString(); if (output.startsWith(ARC_OUTPUT_NOTICE)) { output = output.substring(ARC_OUTPUT_NOTICE_LEN); } LOG.debug("arc command output is: \n{}", output); GsonBuilder gson = new GsonBuilder(); return gson.create().fromJson(output, new TypeToken<HashMap<String, Object>>() { }.getType()); }
From source file:org.sonar.runner.api.CommandExecutor.java
private void closeStreams(Process process) { if (process != null) { IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getOutputStream()); IOUtils.closeQuietly(process.getErrorStream()); }//from w w w .j a va 2 s .c o m }
From source file:com.thoughtworks.go.util.ProcessWrapperTest.java
private Process getMockedProcess(OutputStream outputStream) { Process process = mock(Process.class); when(process.getErrorStream()).thenReturn(mock(InputStream.class)); when(process.getInputStream()).thenReturn(mock(InputStream.class)); when(process.getOutputStream()).thenReturn(outputStream); return process; }