org.codehaus.plexus.util.cli

Class CommandLineUtils

public abstract class CommandLineUtils extends Object

Version: $Id: CommandLineUtils.java 6570 2007-06-30 11:31:19Z olamy $

Author: Trygve Laugstøl

Nested Class Summary
static classCommandLineUtils.StringStreamConsumer
Field Summary
static Mapprocesses
Method Summary
static intexecuteCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr)
static intexecuteCommandLine(Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr)
static PropertiesgetSystemEnvVars()
static PropertiesgetSystemEnvVars(boolean caseSensitive)
Return the shell environment variables.
static booleanisAlive(long pid)
static voidkillProcess(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 (quote(String argument)

Put quotes around the given String if necessary.

If the argument doesn't include spaces or quotes, return it as is.

static Stringquote(String argument, boolean wrapExistingQuotes)

Put quotes around the given String if necessary.

If the argument doesn't include spaces or quotes, return it as is.

static Stringquote(String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes, boolean wrapExistingQuotes)
static StringtoString(String[] line)
static String[]translateCommandline(String toProcess)

Field Detail

processes

private static Map processes

Method Detail

executeCommandLine

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

executeCommandLine

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

getSystemEnvVars

public static Properties getSystemEnvVars()

getSystemEnvVars

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

isAlive

public static boolean isAlive(long pid)

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()

quote

public static String quote(String argument)

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)

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)

toString

public static String toString(String[] line)

translateCommandline

public static String[] translateCommandline(String toProcess)