com.h3c.util

## Class ProcessUtils

- java.lang.Object
- - com.h3c.util.ProcessUtils

-     public final class ProcessUtils
      extends Object

  Set of utilities for launching a process and parsing it's output.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `exec(String command)` Run the specified command and return it's output as a string.
    `static String` | `exec(String[] command)` Run the specified command and return it's output as a string.
    `static String` | `exec(String[] command, String cwd)` Run the specified command and return it's output as a string.
    `static String` | `exec(String command, String cwd)` Run the specified command and return it's output as a string.
    `static BufferedReader` | `execute(String command)` Launch a process and return a buffered reader ready to consume its output.
    `static BufferedReader` | `execute(String[] command, String cwd)` Launch a process and return a buffered reader ready to consume its output.
    `static BufferedReader` | `execute(String command, String cwd)` Launch a process and return a buffered reader ready to consume its output.
    `static BufferedReader` | `open(String file)` Open the system default editor on the specified file.
    `static String` | `slurp(BufferedReader br)` Consume the output of a command from the given buffered reader.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### open

          public static BufferedReader open(String file)

      Open the system default editor on the specified file.
      Parameters:
        `file` - path of the file which should be open
      Returns:
        buffered reader for consuming the process output; null if the process failed to launch correctly

    - #### execute

          public static BufferedReader execute(String command,
                               String cwd)

      Launch a process and return a buffered reader ready to consume its output.
      Parameters:
        `command` - command to be executed
        `cwd` - path to the current working directory in which to launch the subprocess
      Returns:
        buffered reader for consuming the process output; null if the process failed to launch correctly

    - #### execute

          public static BufferedReader execute(String[] command,
                               String cwd)

      Launch a process and return a buffered reader ready to consume its output.
      Parameters:
        `command` - array of command arguments to be executed
        `cwd` - path to the current working directory in which to launch the subprocess
      Returns:
        buffered reader for consuming the process output; null if the process failed to launch correctly

    - #### execute

          public static BufferedReader execute(String command)

      Launch a process and return a buffered reader ready to consume its output.
      Parameters:
        `command` - command to be executed
      Returns:
        buffered reader for consuming the process output; null if the process failed to launch correctly

    - #### exec

          public static String exec(String command)

      Run the specified command and return it's output as a string.
      Parameters:
        `command` - command to be executed
      Returns:
        string containing command standard output; null if the process failed to launch correctly

    - #### exec

          public static String exec(String[] command)

      Run the specified command and return it's output as a string.
      Parameters:
        `command` - array of command arguments to be executed
      Returns:
        string containing command standard output; null if the process failed to launch correctly

    - #### exec

          public static String exec(String[] command,
                    String cwd)

      Run the specified command and return it's output as a string.
      Parameters:
        `command` - array of command arguments to be executed
        `cwd` - path to the current working directory in which to launch the subprocess
      Returns:
        string containing command standard output; null if the process failed to launch correctly

    - #### exec

          public static String exec(String command,
                    String cwd)

      Run the specified command and return it's output as a string.
      Parameters:
        `command` - command to be executed
        `cwd` - path to the current working directory in which to launch the subprocess
      Returns:
        string containing command standard output; null if the process failed to launch correctly

    - #### slurp

          public static String slurp(BufferedReader br)

      Consume the output of a command from the given buffered reader.
      Parameters:
        `br` - buffered reader containing output of a command
      Returns:
        string containing command standard output; null if the process failed to launch correctly

Copyright © 2014. All Rights Reserved.