org.codehaus.plexus.util.cli

Class CommandLineUtils


public abstract class CommandLineUtils
extends java.lang.Object

Version:
$Id: CommandLineUtils.java 5960 2007-02-28 22:35:43Z jdcasey $
Author:
Trygve Laugstøl

Nested Class Summary

static class
CommandLineUtils.StringStreamConsumer

Method Summary

static int
executeCommandLine(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr)
static int
executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr)
static Properties
getSystemEnvVars()
static Properties
getSystemEnvVars(boolean caseSensitive)
Return the shell environment variables.
static boolean
isAlive(long pid)
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)
static String
quote(String argument)
Put quotes around the given String if necessary.
static String
quote(String argument, boolean wrapExistingQuotes)
Put quotes around the given String if necessary.
static String
quote(String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes, boolean wrapExistingQuotes)
static String
toString(String[] line)
static String[]
translateCommandline(String toProcess)

Method Details

executeCommandLine

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

executeCommandLine

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

getSystemEnvVars

public static Properties getSystemEnvVars()
            throws IOException

getSystemEnvVars

public static Properties getSystemEnvVars(boolean caseSensitive)
            throws 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.

isAlive

public static boolean isAlive(long pid)

killProcess

public static void killProcess(long pid)
Parameters:
pid - The pid of command return by Commandline.getPid()

quote

public static String quote(String argument)
            throws CommandLineException
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 String quote(String argument,
                           boolean wrapExistingQuotes)
            throws CommandLineException
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 String quote(String argument,
                           boolean escapeSingleQuotes,
                           boolean escapeDoubleQuotes,
                           boolean wrapExistingQuotes)
            throws CommandLineException

toString

public static String toString(String[] line)

translateCommandline

public static String[] translateCommandline(String toProcess)
            throws Exception