@Override public void flush() throws IOException { process.getOutputStream().flush(); }
@Override public void write(int b) throws IOException { process.getOutputStream().write(b); }
public void flush() throws IOException { process.getOutputStream().flush(); }
public void write(int b) throws IOException { process.getOutputStream().write(b); }
public void closeOutputStream() throws IOException { process.getOutputStream().close(); }
private int exec(String cmd) throws InterruptedException, IOException { ProcessBuilder pb = new ProcessBuilder(exe, cmd); pb.redirectErrorStream(true); Process p = pb.start(); p.getOutputStream().close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); copy(p.getInputStream(), baos); int r = p.waitFor(); if (r!=0) LOGGER.info(exe+" cmd: output:\n"+baos); return r; }
private void close(Process p) { try { IOUtils.closeQuietly(p.getInputStream()); IOUtils.closeQuietly(p.getOutputStream()); IOUtils.closeQuietly(p.getErrorStream()); } finally { if (p != null) { p.destroy(); } } }
private static void closeStreams(@Nullable Process process) { if (process != null) { IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getOutputStream()); IOUtils.closeQuietly(process.getErrorStream()); } }
@Override public void close() throws IOException { process.getOutputStream().close(); try { errWriterThread.join(); outWriterThread.join(); process.waitFor(); } catch (InterruptedException e) { throw new ProcessException(e); } }
private boolean sendCommand(String cmd, @NotNull Process pythonProcess) { try { OutputStreamWriter writer = new OutputStreamWriter(pythonProcess.getOutputStream()); writer.write(cmd); writer.write("\n"); writer.flush(); return true; } catch (Exception e) { _.msg("\nFailed to send command to interpreter: " + cmd); return false; } }
private void startPython(String tmpPath, String args) throws IOException { String pythonBinaryPath = config.getString(PythonOptions.PYTHON_BINARY_PATH); try { Runtime.getRuntime().exec(pythonBinaryPath); } catch (IOException ignored) { throw new RuntimeException(pythonBinaryPath + " does not point to a valid python binary."); } process = Runtime.getRuntime().exec(pythonBinaryPath + " -B " + tmpPath + FLINK_PYTHON_PLAN_NAME + args); new Thread(new StreamPrinter(process.getInputStream())).start(); new Thread(new StreamPrinter(process.getErrorStream())).start(); server = new ServerSocket(0); server.setSoTimeout(50); process.getOutputStream().write("plan\n".getBytes(ConfigConstants.DEFAULT_CHARSET)); process.getOutputStream().flush(); }
private void registerWithCloser(Closer closer) { closer.register(process.getInputStream()); closer.register(process.getOutputStream()); } }
public static Pager create(List<String> command) { try { Process process = new ProcessBuilder() .command(command) .redirectOutput(ProcessBuilder.Redirect.INHERIT) .redirectError(ProcessBuilder.Redirect.INHERIT) .start(); return new Pager(process.getOutputStream(), process); } catch (IOException e) { System.err.println("ERROR: failed to open pager: " + e.getMessage()); return createNullPager(); } }
protected Process sudoWithPass(ArgumentListBuilder args) throws IOException { args.prepend(sudoExe(),"-S"); listener.getLogger().println("$ "+Util.join(args.toList()," ")); ProcessBuilder pb = new ProcessBuilder(args.toCommandArray()); Process p = pb.start(); // TODO: use -p to detect prompt // TODO: detect if the password didn't work PrintStream ps = new PrintStream(p.getOutputStream()); ps.println(rootPassword); ps.println(rootPassword); ps.println(rootPassword); return p; } }.start(listener,rootPassword);
ProcessWrapper(Process process, String processTag, String command, ConsoleOutputStreamConsumer consumer, String encoding, String errorPrefix) { this.process = process; this.processTag = processTag; this.command = command; this.startTime = System.currentTimeMillis(); this.processOutputStream = StreamPumper.pump(process.getInputStream(), new OutputConsumer(consumer), "", encoding); this.processErrorStream = StreamPumper.pump(process.getErrorStream(), new ErrorConsumer(consumer), errorPrefix, encoding); this.processInputStream = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); }
public OutputStream call() throws IOException { Process p = Runtime.getRuntime().exec(cmd, Util.mapToEnv(inherit(envOverrides)), workDir == null ? null : new File(workDir)); List<String> cmdLines = Arrays.asList(cmd); new StreamCopyThread("stdin copier for remote agent on "+cmdLines, p.getInputStream(), out.getOut()).start(); new StreamCopyThread("stderr copier for remote agent on "+cmdLines, p.getErrorStream(), err).start(); // TODO: don't we need to join? return new RemoteOutputStream(p.getOutputStream()); }
public void closeStreams() { closeQuietly(process.getInputStream()); closeQuietly(process.getOutputStream()); closeQuietly(process.getErrorStream()); }
public void close() throws IOException { process.getOutputStream().close(); try { outGobbler.join(); errGobbler.join(); outGobbler.getOutputStream().close(); process.waitFor(); } catch (InterruptedException ex) { throw new RuntimeInterruptedException(ex); } //log.info("getBZip2PipedOutputStream: Closed. "); } }
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; }
private Process mockProcess(final InputStream outputStream, final InputStream errorStream, final OutputStream inputStream) throws InterruptedException { final Process subProcess = mock(Process.class); when(subProcess.waitFor()).thenReturn(42); when(subProcess.getInputStream()).thenReturn(outputStream); when(subProcess.getErrorStream()).thenReturn(errorStream); when(subProcess.getOutputStream()).thenReturn(inputStream); return subProcess; }