org.codehaus.plexus.util.cli

## Class CommandLineUtils

- java.lang.Object
- - org.codehaus.plexus.util.cli.CommandLineUtils

-     public abstract class CommandLineUtils
      extends java.lang.Object

  Version:
    $Id: CommandLineUtils.java 8253 2009-06-05 00:18:27Z igorife $
  Author:
    Trygve Laugstøl

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CommandLineUtils.StringStreamConsumer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CommandLineUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addShutdownHook()`
    `static int` | `executeCommandLine(Commandline cl, java.io.InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr)`
    `static int` | `executeCommandLine(Commandline cl, java.io.InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds)`
    `static int` | `executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr)`
    `static int` | `executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds)`
    `static java.util.Properties` | `getSystemEnvVars()` Gets the shell environment variables for this process.
    `static java.util.Properties` | `getSystemEnvVars(boolean caseSensitive)` Return the shell environment variables.
    `static boolean` | `isAlive(long pid)`
    `static boolean` | `isAlive(java.lang.Process p)`
    `static void` | `killProcess(long pid)` Kill a process launched by executeCommandLine methods.
    `static java.lang.String` | `quote(java.lang.String argument)` Deprecated. Use `StringUtils.quoteAndEscape(String, char, char[], char[], char, boolean)`, `StringUtils.quoteAndEscape(String, char, char[], char, boolean)`, or `StringUtils.quoteAndEscape(String, char)` instead.
    `static java.lang.String` | `quote(java.lang.String argument, boolean wrapExistingQuotes)` Deprecated. Use `StringUtils.quoteAndEscape(String, char, char[], char[], char, boolean)`, `StringUtils.quoteAndEscape(String, char, char[], char, boolean)`, or `StringUtils.quoteAndEscape(String, char)` instead.
    `static java.lang.String` | `quote(java.lang.String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes, boolean wrapExistingQuotes)` Deprecated. Use `StringUtils.quoteAndEscape(String, char, char[], char[], char, boolean)`, `StringUtils.quoteAndEscape(String, char, char[], char, boolean)`, or `StringUtils.quoteAndEscape(String, char)` instead.
    `static void` | `removeShutdownHook(boolean execute)`
    `static java.lang.String` | `toString(java.lang.String[] line)`
    `static java.lang.String[]` | `translateCommandline(java.lang.String toProcess)`

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

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

- - ### Constructor Detail

    - #### CommandLineUtils

          public CommandLineUtils()

  - ### Method Detail

    - #### addShutdownHook

          public static void addShutdownHook()

    - #### removeShutdownHook

          public static void removeShutdownHook(boolean execute)

    - #### executeCommandLine

          public static int executeCommandLine(Commandline cl,
                                               StreamConsumer systemOut,
                                               StreamConsumer systemErr)
                                        throws CommandLineException

      Throws:
        `CommandLineException`

    - #### executeCommandLine

          public static int executeCommandLine(Commandline cl,
                                               StreamConsumer systemOut,
                                               StreamConsumer systemErr,
                                               int timeoutInSeconds)
                                        throws CommandLineException

      Throws:
        `CommandLineException`

    - #### executeCommandLine

          public static int executeCommandLine(Commandline cl,
                                               java.io.InputStream systemIn,
                                               StreamConsumer systemOut,
                                               StreamConsumer systemErr)
                                        throws CommandLineException

      Throws:
        `CommandLineException`

    - #### executeCommandLine

          public static int executeCommandLine(Commandline cl,
                                               java.io.InputStream systemIn,
                                               StreamConsumer systemOut,
                                               StreamConsumer systemErr,
                                               int timeoutInSeconds)
                                        throws CommandLineException

      Parameters:
        `cl` -
        `systemIn` -
        `systemOut` -
        `systemErr` -
        `timeoutInSeconds` -
      Returns:
      Throws:
        `CommandLineException` - or CommandLineTimeOutException if time out occurs

    - #### getSystemEnvVars

          public static java.util.Properties getSystemEnvVars()
                                                       throws java.io.IOException

      Gets the shell environment variables for this process. Note that the returned mapping from variable names to values will always be case-sensitive regardless of the platform, i.e. `getSystemEnvVars().get("path")` and `getSystemEnvVars().get("PATH")` will in general return different values. However, on platforms with case-insensitive environment variables like Windows, all variable names will be normalized to upper case.
      Returns:
        The shell environment variables, can be empty but never `null`.
      Throws:
        `java.io.IOException` - If the environment variables could not be queried from the shell.

    - #### getSystemEnvVars

          public static java.util.Properties getSystemEnvVars(boolean caseSensitive)
                                                       throws java.io.IOException

      Return the shell environment variables. If `caseSensitive == true`, then envar keys will all be upper-case.
      Parameters:
        `caseSensitive` - Whether environment variable keys should be treated case-sensitively.
      Returns:
        Properties object of (possibly modified) envar keys mapped to their values.
      Throws:
        `java.io.IOException`

    - #### killProcess

          public static void killProcess(long pid)

      Kill a process launched by executeCommandLine methods. Doesn't work correctly on windows, only the cmd process will be destroy but not the sub process (Bug ID 4770092)
      Parameters:
        `pid` - The pid of command return by Commandline.getPid()

    - #### isAlive

          public static boolean isAlive(long pid)

    - #### isAlive

          public static boolean isAlive(java.lang.Process p)

    - #### translateCommandline

          public static java.lang.String[] translateCommandline(java.lang.String toProcess)
                                                         throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### quote

          public static java.lang.String quote(java.lang.String argument)
                                        throws CommandLineException

      Deprecated. Use `StringUtils.quoteAndEscape(String, char, char[], char[], char, boolean)`, `StringUtils.quoteAndEscape(String, char, char[], char, boolean)`, or `StringUtils.quoteAndEscape(String, char)` instead.

      Put quotes around the given String if necessary.

      If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single quotes - else surround the argument by double quotes.

      Throws:
        `CommandLineException` - if the argument contains both, single and double quotes.

    - #### quote

          public static java.lang.String quote(java.lang.String argument,
                                               boolean wrapExistingQuotes)
                                        throws CommandLineException

      Deprecated. Use `StringUtils.quoteAndEscape(String, char, char[], char[], char, boolean)`, `StringUtils.quoteAndEscape(String, char, char[], char, boolean)`, or `StringUtils.quoteAndEscape(String, char)` instead.

      Put quotes around the given String if necessary.

      If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single quotes - else surround the argument by double quotes.

      Throws:
        `CommandLineException` - if the argument contains both, single and double quotes.

    - #### quote

          public static java.lang.String quote(java.lang.String argument,
                                               boolean escapeSingleQuotes,
                                               boolean escapeDoubleQuotes,
                                               boolean wrapExistingQuotes)
                                        throws CommandLineException

      Deprecated. Use `StringUtils.quoteAndEscape(String, char, char[], char[], char, boolean)`, `StringUtils.quoteAndEscape(String, char, char[], char, boolean)`, or `StringUtils.quoteAndEscape(String, char)` instead.
      Throws:
        `CommandLineException`

    - #### toString

          public static java.lang.String toString(java.lang.String[] line)