Java Reference
In-Depth Information
String cmd = "/bin/ls " + opts + " " + dir;
Process child = Runtime.getRuntime().exec(cmd);
Process
is an abstract class. Each implementation of a Java virtual ma-
chine may provide one or more appropriate extended classes of
Process
that can interact with processes on the underlying system. Such classes
might have extended functionality that would be useful for programming
on the underlying system. The local documentation should contain in-
formation about this extended functionality.
Note that there is no requirement that the child process execute asyn-
chronously or concurrently with respect to the parent processin a par-
ticular system
exec
could appear to block until the child process termin-
ates.
Exercise 23.1
: Write the
plugTogether
method. You will need threads.
23.2.2. Process Environments
Two other forms of
Runtime.exec
enable you to specify a set of
environ-
ment variables,
which are system-dependent values that can be quer-
ied as desired by the new process. Environment variables are passed
to
exec
as a
String
array; each element of the array specifies the name
and value of an environment variable in the form
name
=
value
. The name
cannot contain any spaces, although the value can be any string. The
environment variables are passed as the second parameter:
public Process
exec(String[] cmdArray, String[] env)
throws IOException
public Process
exec(String command, String[] env)
throws IOException