|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectutil.Shell
public class Shell
Utility class which acts like a system shell manipulable from Java code.
| Field Summary | |
|---|---|
protected File |
cwd
The current working directory. |
protected int |
lastExitValue
The exit value of the last command executed. |
protected PrintStream |
stderr
The stream to use for standard error. |
protected InputStream |
stdin
The stream to use for standard input. |
protected PrintStream |
stdout
The stream to use for standard output. |
| Constructor Summary | |
|---|---|
Shell()
|
|
| Method Summary | |
|---|---|
Shell |
chdir(File dir)
Change directory. |
Process |
fork(String... cmdLine)
Run a process within this shell, in the background. |
File |
getCwd()
Get the current directory. |
int |
getLastExitValue()
|
PrintStream |
getStdErr()
|
InputStream |
getStdIn()
|
PrintStream |
getStdOut()
|
int |
run(String... cmdLine)
Run a process within this shell. |
int |
runClass(Class<?> cls,
String... args)
Run a Java class as a process within this shell. |
Shell |
setStdErr(PrintStream stderr)
|
Shell |
setStdIn(InputStream stdin)
|
Shell |
setStdOut(PrintStream stdout)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected File cwd
protected PrintStream stdout
protected PrintStream stderr
protected InputStream stdin
protected int lastExitValue
| Constructor Detail |
|---|
public Shell()
| Method Detail |
|---|
public File getCwd()
pwd.
public Shell chdir(File dir)
throws IOException
cd.
dir - The directory to change to.
this, for chaining.
IOException - If cwd is not a directory or does not exist.public PrintStream getStdErr()
public Shell setStdErr(PrintStream stderr)
stderr - A stream which will receive anything a child process sends
to its standard error stream. By default this will be System.err, that
is, the system-wide standard error stream.
this, for chaining.public InputStream getStdIn()
public Shell setStdIn(InputStream stdin)
stdin - A stream to be connected to standard input for child
processes. By default this will be System.in, that is, the system-wide
standard input stream.
this, for chaining.public PrintStream getStdOut()
public Shell setStdOut(PrintStream stdout)
stdout - A stream which will receive anything a child process sends
to its standard output stream. By default this will be System.err, that
is, the system-wide standard output stream.
this, for chaining.
public int run(String... cmdLine)
throws IOException,
InterruptedException
cmdLine - The command line, split into its arguments. No shell-like
processing - word splitting, variable substitution, etc. - will be
performed.
IOException - If the program cannot be found or run.
InterruptedException - If this thread is interrupted while the
program is running.
public Process fork(String... cmdLine)
throws IOException
cmdLine - The command line, split into its arguments. No shell-like
processing - word splitting, variable substitution, etc. - will be
performed.
null if it could not be started.
IOException - If the program cannot be found or run.
public int runClass(Class<?> cls,
String... args)
throws IOException,
InterruptedException
cls - The class to run. Must declare a method with signature
public static void main(String[]).args - Arguments to pass to the class's main method.
IOException - For any problems relating to I/O (not being able to
access the class file, etc.)
InterruptedException - If this thread is interrupted while the
class is running.
IllegalArgumentException - If cls does not declare a
method with the correct signature.public int getLastExitValue()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||