/** * 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(); } }
IOPipe.create(in, out).lineProcessor(lp).run(); assertEquals("[foo][bar]", out.toString().replaceAll("[\\r\\n]", "")); in = new TestReader("foo\nbar"); out = new TestWriter(); IOPipe.create(in, out).lineProcessor(lp2).run(); assertEquals("bar", out.toString().replaceAll("[\\r\\n]", "")); in2 = new TestInputStream("foo\nbar"); out2 = new TestOutputStream(); IOPipe.create(in2, out2).lineProcessor(lp).run(); assertEquals("[foo][bar]", out2.toString().replaceAll("[\\r\\n]", ""));