/** * Run this command and pipes the output to the specified writer or output stream. * * @return The exit code from the process. * @throws IOException * @throws InterruptedException */ public int run() throws IOException, InterruptedException { if (pb.command().size() == 0) throw new IOException("No command specified in ProcBuilder."); try { logWriters.append(divider).append('\n').flush(); logWriters.append(join(pb.command(), " ")).append('\n').flush(); p = pb.start(); IOPipe.create(p.getInputStream(), outWriters).lineProcessor(lp).byLines(byLines).run(); int rc = p.waitFor(); logWriters.append("Exit: ").append(String.valueOf(p.exitValue())).append('\n').flush(); if (rc > maxExitStatus) throw new IOException("Return code "+rc+" from command " + join(pb.command(), " ")); return rc; } finally { close(); } }
/** * Run this command and pipes the output to the specified writer or output stream. * * @return The exit code from the process. * @throws IOException * @throws InterruptedException */ public int run() throws IOException, InterruptedException { if (pb.command().size() == 0) throw new IOException("No command specified in ProcBuilder."); try { logWriters.append(divider).append('\n').flush(); logWriters.append(join(pb.command(), " ")).append('\n').flush(); p = pb.start(); IOPipe.create(p.getInputStream(), outWriters).lineProcessor(lp).byLines(byLines).run(); int rc = p.waitFor(); logWriters.append("Exit: ").append(String.valueOf(p.exitValue())).append('\n').flush(); if (rc > maxExitStatus) throw new IOException("Return code "+rc+" from command " + join(pb.command(), " ")); return rc; } finally { close(); } }
/** * Run this command and pipes the output to the specified writer or output stream. * * @return The exit code from the process. * @throws IOException * @throws InterruptedException */ public int run() throws IOException, InterruptedException { if (pb.command().size() == 0) throw new IOException("No command specified in ProcBuilder."); try { logWriters.append(divider).append('\n').flush(); logWriters.append(join(pb.command(), " ")).append('\n').flush(); p = pb.start(); IOPipe.create(p.getInputStream(), outWriters).lineProcessor(lp).byLines(byLines).run(); int rc = p.waitFor(); logWriters.append("Exit: ").append(String.valueOf(p.exitValue())).append('\n').flush(); if (rc > maxExitStatus) throw new IOException("Return code "+rc+" from command " + join(pb.command(), " ")); return rc; } finally { close(); } }
StringWriter sw = new StringWriter(); writers.add(sw, true); IOPipe.create(isr, writers).byLines(byLines).run(); return new StringReader(sw.toString());
StringWriter sw = new StringWriter(); writers.add(sw, true); IOPipe.create(isr, writers).byLines(byLines).run(); return new StringReader(sw.toString());
StringWriter sw = new StringWriter(); writers.add(sw, true); IOPipe.create(isr, writers).byLines(byLines).run(); return new StringReader(sw.toString());
@Test public void testByLines() throws Exception { TestReader in; TestWriter out; in = new TestReader("foo\nbar"); out = new TestWriter() { @Override public void write(String s) { super.write("["+s+"]"); } }; IOPipe.create(in, out).byLines().run(); assertEquals("[foo][][bar][]", out.toString().replaceAll("[\\r\\n]", "")); in = new TestReader("foo\nbar"); out = new TestWriter() { @Override public void write(String s) { super.write("["+s+"]"); } }; IOPipe.create(in, out).byLines(true).run(); assertEquals("[foo][][bar][]", out.toString().replaceAll("[\\r\\n]", "")); in = new TestReader("foo\nbar"); out = new TestWriter() { @Override public void write(String s) { super.write("["+s+"]"); } }; IOPipe.create(in, out).byLines(false).run(); assertEquals("foo\nbar", out.toString()); }