Java exec exec(String command)

Here you can find the source of exec(String command)

Description

Utility function for debugging.

License

Open Source License

Parameter

Parameter Description
command a parameter

Declaration

static void exec(String command) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {
    /**/*from  www  .  j av a2 s .c  om*/
     * Utility function for debugging. Executes a command and pipes the result to
     * System.err
     *
     * @param command
     */
    static void exec(String command) {
        try {
            Process p = Runtime.getRuntime().exec(command);
            BufferedReader stdInput = new BufferedReader(
                    new InputStreamReader(p.getInputStream()));
            BufferedReader stdError = new BufferedReader(
                    new InputStreamReader(p.getErrorStream()));

            // read the output from the command
            while ((command = stdInput.readLine()) != null) {
                System.err.println(command);
            }

            // read any errors from the attempted command
            while ((command = stdError.readLine()) != null) {
                System.err.println(command);
            }
        } catch (IOException e) {
            System.err.println("exception happened - here's what I know: ");
            e.printStackTrace();
        }
    }
}

Related

  1. exec(String cmd)
  2. exec(String cmd)
  3. exec(String cmd, File dir)
  4. exec(String command)
  5. exec(String command)
  6. exec(String command)
  7. exec(String command)
  8. exec(String command)
  9. exec(String command, String workingDir)