img
To create a process using ProcessBuilder, simply create an instance of ProcessBuilder,
specifying the name of the program and any needed arguments. To begin execution of the
program, call start( ) on that instance. Here is an example that executes the Windows text
editor notepad. Notice that it specifies the name of the file to edit as an argument.
class PBDemo {
public static void main(String args[]) {
try {
ProcessBuilder proc =
new ProcessBuilder("notepad.exe", "testfile");
proc.start();
} catch (Exception e) {
System.out.println("Error executing notepad.");
}
}
}
Method
Description
List<String> command( )
Returns a reference to a List that contains the
name of the program and its arguments. Changes
to this list af fect the invoking process.
ProcessBuilder command(List<String> args) Sets the name of the program and its arguments
to those specified by args. Changes to this list
af fect the invoking process. Returns a reference to
the invoking object.
ProcessBuilder command(String ... args)
Sets the name of the program and its arguments
to those specified by args. Returns a reference to
the invoking object.
File director y( )
Returns the current working director y of the invoking
object. This value will be null if the director y is the
same as that of the Java program that star ted the
process.
ProcessBuilder director y(File dir)
Sets the current working director y of the invoking
object. Returns a reference to the invoking object.
Map<String, String> environment( )
Returns the environmental variables associated
with the invoking object as key/value pairs.
boolean redirectErrorStream( )
Returns true if the standard error stream has been
redirected to the standard output stream. Returns
false if the streams are separate.
ProcessBuilder
If merge is true, then the standard error stream is
redirectErrorStream(boolean merge)
redirected to standard output. If merge is false,
the streams are separated, which is the default
state. Returns a reference to the invoking object.
Process star t( )
Begins the process specified by the invoking object.
throws IOException
In other words, it runs the specified program.
TABLE 16-12
The Methods Defined by ProcessBuilder
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home