Commandline objects help handling command lines specifying processes to
execute.
The class can be used to define a command line as nested elements or as a
helper to define a command line by an application.
<someelement>
<acommandline executable="/executable/to/run">
<argument value="argument 1" />
<argument line="argument_1 argument_2 argument_3" />
<argument value="argument 4" />
</acommandline>
</someelement>
The element
someelement
must provide a method
createAcommandline
which returns an instance of this class.
OS_NAME
protected static final String OS_NAME
WINDOWS
protected static final String WINDOWS
arguments
protected Vector arguments
envVars
protected Vector envVars
executable
protected String executable
newEnvironment
private boolean newEnvironment
workingDir
private File workingDir
addArguments
public void addArguments(String[] line)
addEnvironment
public void addEnvironment(String name,
String value)
Add an environment variable
addSystemEnvironment
public void addSystemEnvironment()
throws Exception
Add system environment variables
clear
public void clear()
Clear out the whole command line.
clearArgs
public void clearArgs()
Clear out the arguments but leave the executable in place for another operation.
clone
public Object clone()
createArgument
public Commandline.Argument createArgument()
Creates an argument object.
Each commandline object has at most one instance of the
argument class. This method calls
this.createArgument(false)
.
createArgument
public Commandline.Argument createArgument(boolean insertAtStart)
Creates an argument object and adds it to our list of args.
Each commandline object has at most one instance of the
argument class.
insertAtStart
- if true, the argument is inserted at the
beginning of the list of args, otherwise it is appended.
createMarker
public Commandline.Marker createMarker()
Return a marker.
This marker can be used to locate a position on the
commandline - to insert something for example - when all
parameters have been set.
getArguments
public String[] getArguments()
Returns all arguments defined by addLine
,
addValue
or the argument object.
getCommandline
public String[] getCommandline()
Returns the executable and all defined arguments.
getCurrentEnvironment
public String[] getCurrentEnvironment()
Return the current list of environment variables or null if user
doesn't have add any variable.
getEnvironments
public String[] getEnvironments()
Return the list of environment variables
getExecutable
public String getExecutable()
getPid
public long getPid()
getShell
public Shell getShell()
Get the shell to be used in this command line.
getShellCommandline
public String[] getShellCommandline()
Returns the shell, executable and all defined arguments.
getSystemEnvVars
public Properties getSystemEnvVars()
throws Exception
getWorkingDirectory
public File getWorkingDirectory()
quoteArgument
public static String quoteArgument(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.
setDefaultShell
private void setDefaultShell()
Sets the shell or command-line interpretor for the detected operating system,
and the shell arguments.
setExecutable
public void setExecutable(String executable)
Sets the executable to run.
setPid
public void setPid(long pid)
setShell
public void setShell(Shell shell)
Allows to set the shell to be used in this command line.
setWorkingDirectory
public void setWorkingDirectory(String path)
Sets execution directory.
toString
public String toString()
toString
public static String toString(String[] line)
translateCommandline
public static String[] translateCommandline(String toProcess)
throws Exception