Show the return value of a process using a stream

0

I recently developed a code that returned the number 0 when I called a process and it ended correctly. My question is how I could do the same thing but using a Stream stream since it is developed with a waitFor () and with a simple sout. I suspect that it is done with a getInputStream. Thanks.

Below my code made:

public static void main(String[] args) {

    if(args.length < 1){

        System.out.println("");
        System.exit(-1);

    }

    ProcessBuilder pb = new ProcessBuilder(args[0]);

    int codigoSalida;

    try{

        Process p = pb.start();

        codigoSalida = p.waitFor();

        System.out.println(codigoSalida);


    }

    catch(InterruptedException | IOException e){

        System.out.println("Error " + e);
    }


}
    
asked by deserrt 04.11.2018 в 22:01
source

0 answers