Here you can find the source of execPrint(final boolean out, final String... command)
Parameter | Description |
---|---|
out | whether the output should be shown on stdout |
command | the command and arguments to run |
Parameter | Description |
---|---|
IOException | if the program cannot be launched |
public static int execPrint(final boolean out, final String... command) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**/* www.j a v a 2s .c o m*/ * Executes the command, optionally copying output to standard output. * * @param out whether the output should be shown on stdout * @param command the command and arguments to run * @return the exit code of the program * @throws IOException if the program cannot be launched */ public static int execPrint(final boolean out, final String... command) throws IOException { final ProcessBuilder builder = new ProcessBuilder(command); builder.redirectErrorStream(true); final Process p = builder.start(); final InputStream is = p.getInputStream(); int c; // Read-print loop while ((c = is.read()) >= 0) if (out) { System.out.write(c); System.out.flush(); } is.close(); return p.exitValue(); } }