ProcessImplpublic final class ProcessImpl extends Process
Fields Summary |
---|
private long | handle | private FileDescriptor | stdin_fd | private FileDescriptor | stdout_fd | private FileDescriptor | stderr_fd | private OutputStream | stdin_stream | private InputStream | stdout_stream | private InputStream | stderr_stream |
Constructors Summary |
---|
private ProcessImpl(String[] cmd, String envblock, String path, boolean redirectErrorStream)
// Win32 CreateProcess requires cmd[0] to be normalized
cmd[0] = new File(cmd[0]).getPath();
StringBuilder cmdbuf = new StringBuilder(80);
for (int i = 0; i < cmd.length; i++) {
if (i > 0) {
cmdbuf.append(' ");
}
String s = cmd[i];
if (s.indexOf(' ") >= 0 || s.indexOf('\t") >= 0) {
if (s.charAt(0) != '"") {
cmdbuf.append('"");
cmdbuf.append(s);
if (s.endsWith("\\")) {
cmdbuf.append("\\");
}
cmdbuf.append('"");
} else if (s.endsWith("\"")) {
/* The argument has already been quoted. */
cmdbuf.append(s);
} else {
/* Unmatched quote for the argument. */
throw new IllegalArgumentException();
}
} else {
cmdbuf.append(s);
}
}
String cmdstr = cmdbuf.toString();
stdin_fd = new FileDescriptor();
stdout_fd = new FileDescriptor();
stderr_fd = new FileDescriptor();
handle = create(cmdstr, envblock, path, redirectErrorStream,
stdin_fd, stdout_fd, stderr_fd);
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
stdin_stream =
new BufferedOutputStream(new FileOutputStream(stdin_fd));
stdout_stream =
new BufferedInputStream(new FileInputStream(stdout_fd));
stderr_stream =
new FileInputStream(stderr_fd);
return null;
}
});
|
Methods Summary |
---|
private native void | close()
| private native long | create(java.lang.String cmdstr, java.lang.String envblock, java.lang.String dir, boolean redirectErrorStream, java.io.FileDescriptor in_fd, java.io.FileDescriptor out_fd, java.io.FileDescriptor err_fd)
| public native void | destroy()
| public native int | exitValue()
| public void | finalize()
close();
| public java.io.InputStream | getErrorStream()
return stderr_stream;
| public java.io.InputStream | getInputStream()
return stdout_stream;
| public java.io.OutputStream | getOutputStream()
return stdin_stream;
| static java.lang.Process | start(java.lang.String[] cmdarray, java.util.Map environment, java.lang.String dir, boolean redirectErrorStream)
String envblock = ProcessEnvironment.toEnvironmentBlock(environment);
return new ProcessImpl(cmdarray, envblock, dir, redirectErrorStream);
| public native int | waitFor()
|
|