|
Préférences
Moteurs de recherche
|
|||||||||||||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.5.0
java.lang
|
Constructor Summary | |
---|---|
ProcessBuilder(List<String> command)
Constructs a process builder with the specified operating system program and arguments. |
|
ProcessBuilder(String... command)
Constructs a process builder with the specified operating system program and arguments. |
Method Summary | |
---|---|
List<String> |
command()
Returns this process builder's operating system program and arguments. |
ProcessBuilder |
command(List<String> command)
Sets this process builder's operating system program and arguments. |
ProcessBuilder |
command(String... command)
Sets this process builder's operating system program and arguments. |
File |
directory()
Returns this process builder's working directory. |
ProcessBuilder |
directory(File directory)
Sets this process builder's working directory. |
Map<String,String> |
environment()
Returns a string map view of this process builder's environment. |
boolean |
redirectErrorStream()
Tells whether this process builder merges standard error and standard output. |
ProcessBuilder |
redirectErrorStream(boolean redirectErrorStream)
Sets this process builder's redirectErrorStream property. |
Process |
start()
Starts a new process using the attributes of this process builder. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ProcessBuilder(List<String> command)
command
list. Subsequent
updates to the list will be reflected in the state of the
process builder. It is not checked whether
command
corresponds to a valid operating system
command.
command
- The list containing the program and its arguments
NullPointerException
- If the argument is null
public ProcessBuilder(String... command)
command
array, in the same order. It is not checked whether
command
corresponds to a valid operating system
command.
command
- A string array containing the program and its argumentsMethod Detail |
---|
public ProcessBuilder command(List<String> command)
command
list. Subsequent updates to the list will
be reflected in the state of the process builder. It is not
checked whether command
corresponds to a valid
operating system command.
command
- The list containing the program and its arguments
NullPointerException
- If the argument is null
public ProcessBuilder command(String... command)
command
array, in the same order. It is not
checked whether command
corresponds to a valid
operating system command.
command
- A string array containing the program and its arguments
public List<String> command()
public Map<String,String> environment()
System.getenv()
). Subprocesses subsequently started by
this object's start()
method will use this map as
their environment.
The returned object may be modified using ordinary Map
operations. These modifications will be
visible to subprocesses started via the start()
method. Two ProcessBuilder
instances always
contain independent process environments, so changes to the
returned map will never be reflected in any other
ProcessBuilder
instance or the values returned by
System.getenv
.
If the system does not support environment variables, an empty map is returned.
The returned map does not permit null keys or values.
Attempting to insert or query the presence of a null key or
value will throw a NullPointerException
.
Attempting to query the presence of a key or value which is not
of type String
will throw a ClassCastException
.
The behavior of the returned map is system-dependent. A
system may not allow modifications to environment variables or
may forbid certain variable names or values. For this reason,
attempts to modify the map may fail with
UnsupportedOperationException
or
IllegalArgumentException
if the modification is not permitted by the operating system.
Since the external format of environment variable names and values is system-dependent, there may not be a one-to-one mapping between them and Java's Unicode strings. Nevertheless, the map is implemented in such a way that environment variables which are not modified by Java code will have an unmodified native representation in the subprocess.
The returned map and its collection views may not obey the
general contract of the Object.equals(java.lang.Object)
and
Object.hashCode()
methods.
The returned map is typically case-sensitive on all platforms.
If a security manager exists, its
checkPermission
method is called with a
permission. This may result in a RuntimePermission
("getenv.*")SecurityException
being
thrown.
When passing information to a Java subprocess, system properties are generally preferred over environment variables.
SecurityException
- If a security manager exists and its
checkPermission
method doesn't allow access to the process environmentRuntime.exec(String[],String[],java.io.File)
,
System.getenv()
public File directory()
start()
method will use this as their working directory.
The returned value may be null
-- this means to use
the working directory of the current Java process, usually the
directory named by the system property user.dir
,
as the working directory of the child process.
public ProcessBuilder directory(File directory)
start()
method will use this as their working directory.
The argument may be null
-- this means to use the
working directory of the current Java process, usually the
directory named by the system property user.dir
,
as the working directory of the child process.
directory
- The new working directory
public boolean redirectErrorStream()
If this property is true
, then any error output
generated by subprocesses subsequently started by this object's
start()
method will be merged with the standard
output, so that both can be read using the
Process.getInputStream()
method. This makes it easier
to correlate error messages with the corresponding output.
The initial value is false
.
redirectErrorStream
propertypublic ProcessBuilder redirectErrorStream(boolean redirectErrorStream)
redirectErrorStream
property.
If this property is true
, then any error output
generated by subprocesses subsequently started by this object's
start()
method will be merged with the standard
output, so that both can be read using the
Process.getInputStream()
method. This makes it easier
to correlate error messages with the corresponding output.
The initial value is false
.
redirectErrorStream
- The new property value
public Process start() throws IOException
The new process will
invoke the command and arguments given by command()
,
in a working directory as given by directory()
,
with a process environment as given by environment()
.
This method checks that the command is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty list of non-null strings.
If there is a security manager, its
checkExec
method is called with the first component of this object's
command
array as its argument. This may result in
a SecurityException
being thrown.
Starting an operating system process is highly system-dependent. Among the many things that can go wrong are:
In such cases an exception will be thrown. The exact nature
of the exception is system-dependent, but it will always be a
subclass of IOException
.
Subsequent modifications to this process builder will not
affect the returned Process
.
Process
object for managing the subprocess
NullPointerException
- If an element of the command list is null
IndexOutOfBoundsException
- If the command is an empty list (has size 0
)
SecurityException
- If a security manager exists and its
checkExec
method doesn't allow creation of the subprocess
IOException
- If an I/O error occursRuntime.exec(String[], String[], java.io.File)
,
SecurityManager.checkExec(String)