List of usage examples for java.lang Process getOutputStream
public abstract OutputStream getOutputStream();
From source file:com.netxforge.oss2.core.utils.ProcessExec.java
/** * <p>exec</p>/* w w w. j a va 2 s .co m*/ * * @param cmd an array of {@link java.lang.String} objects. * @return a int. * @throws java.io.IOException if any. * @throws java.lang.InterruptedException if any. */ public int exec(String[] cmd) throws IOException, InterruptedException { Process p = Runtime.getRuntime().exec(cmd); p.getOutputStream().close(); PrintInputStream out = new PrintInputStream(p.getInputStream(), m_out); PrintInputStream err = new PrintInputStream(p.getErrorStream(), m_err); Thread t1 = new Thread(out, this.getClass().getSimpleName() + "-stdout"); Thread t2 = new Thread(err, this.getClass().getSimpleName() + "-stderr"); t1.start(); t2.start(); int exitVal = p.waitFor(); t1.join(); t2.join(); return exitVal; }
From source file:org.inria.myriads.snoozenode.executor.thread.ExecutorThread.java
/** * Closes process streams./* w w w . ja v a 2 s .c om*/ * * @param process The process */ private void closeStreams(Process process) { log_.debug("Closing streams!"); IOUtils.closeQuietly(process.getOutputStream()); IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getErrorStream()); log_.debug("Streams closed!"); }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.code.RServe.java
/** * Evaluates and prints an expression to the Plugin console executed in a job. * // w ww . jav a 2 s . c o m * @param expression * a R expression as a string. */ public static void printJob(String expression) {// helper class to print if (RState.isBusy() == false) { RState.setBusy(true); REvaluateJob job = new REvaluateJob(expression); job.addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { if (event.getResult().isOK()) { int countDev = getDisplayNumber(); RState.setBusy(false); if (countDev > 0) { RServe.closeAndDisplay(); } System.out.flush(); } else { RState.setBusy(false); System.out.flush(); } } }); // job.setSystem(true); job.schedule(); } else { Process p; IPreferenceStore store = Activator.getDefault().getPreferenceStore(); if (store.getBoolean("RSERVE_NATIVE_START")) { ConsolePageParticipant consol = ConsolePageParticipant.getConsolePageParticipantInstance(); p = consol.getRProcess(); } else { p = RConnectionJob.getProc(); } // Write to the output! if (p != null) { final OutputStream os = p.getOutputStream(); final OutputStreamWriter osw = new OutputStreamWriter(os); final BufferedWriter bw = new BufferedWriter(osw, 100); try { bw.write(expression); bw.newLine(); os.flush(); bw.flush(); // bw.close(); System.out.flush(); } catch (IOException e) { System.err.println(""); } } MsgDialog.message("Rserve is busy!"); } }
From source file:com.github.pemapmodder.pocketminegui.gui.server.ServerMainActivity.java
public void setProcess(Process process) { this.process = process; stdin = process.getOutputStream(); stdout = process.getInputStream();//from www . j a v a 2 s . co m stdoutBuffered = new NonBlockingANSIReader(stdout); stdoutBuffered.start(); }
From source file:com.dirtyunicorns.hfm.mainFragment.java
public void RunAsRoot(String string) throws IOException { Process P = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(P.getOutputStream()); os.writeBytes(string + "\n"); os.writeBytes("exit\n"); os.flush();/*from w ww.j a va2 s . com*/ }
From source file:org.eclipse.cdt.boost.build.core.internal.builder.B2Process.java
private B2Process(Process process) { fOut = new OutputStreamWriter(process.getOutputStream()); fIn = new BufferedReader(new InputStreamReader(process.getInputStream())); }
From source file:com.orange.clara.cloud.servicedbdumper.dbdumper.core.CoreRestorer.java
protected void runRestore(DatabaseDriver databaseDriver, String fileName) throws IOException, InterruptedException, RunProcessException { int i = 1;/*from ww w. j ava2s. c o m*/ while (true) { Process p = this.runCommandLine(databaseDriver.getRestoreCommandLine(), true); this.filer.retrieve(p.getOutputStream(), fileName); p.waitFor(); if (p.exitValue() == 0) { break; } if (i >= this.dbCommandRetry) { throw new RunProcessException("\nError during process (exit code is " + p.exitValue() + "): "); } logger.warn("Retry {}/{}: fail to restore data for file {}.", i, dbCommandRetry, fileName); Thread.sleep(10000); i++; } }
From source file:es.ua.dlsi.patch.translation.LocalApertiumTranslator.java
public Set<String> getTranslation(final String input) { Set<String> output = new HashSet<>(); String finalline = ""; // pull from the map if already there try {/* w ww .jav a2s. co m*/ String[] command = { "apertium", "-u", langCmd }; ProcessBuilder probuilder = new ProcessBuilder(command); Process process = probuilder.start(); OutputStream stdin = process.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin)); writer.write(input); writer.newLine(); writer.flush(); writer.close(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { finalline += line; } br.close(); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } output.add(finalline); return output; }
From source file:rsc.backend.connections.localConnection.LocalConnection.java
public Streams execute(String command) throws IOException { Process p; p = Runtime.getRuntime().exec(command); return createStreams(p.getInputStream(), p.getOutputStream(), p.getErrorStream()); }
From source file:org.apache.metron.rest.service.impl.PcapToPdmlScriptWrapper.java
public InputStream execute(String scriptPath, FileSystem fileSystem, Path pcapPath) throws IOException { ProcessBuilder processBuilder = getProcessBuilder(scriptPath, pcapPath.toUri().getPath()); Process process = processBuilder.start(); InputStream rawInputStream = getRawInputStream(fileSystem, pcapPath); OutputStream processOutputStream = process.getOutputStream(); IOUtils.copy(rawInputStream, processOutputStream); rawInputStream.close();//from w ww. j av a 2 s . co m if (process.isAlive()) { // need to close processOutputStream if script doesn't exit with an error processOutputStream.close(); return process.getInputStream(); } else { String errorMessage = IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8); throw new IOException(errorMessage); } }