FileDocCategorySizeDatePackage
ProcessImpl.javaAPI DocJava SE 6 API3248Tue Jun 10 00:32:44 BST 2008java.lang

ProcessImpl

public 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 voidclose()

private native longcreate(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 voiddestroy()

public native intexitValue()

public voidfinalize()

	close();
    
public java.io.InputStreamgetErrorStream()

	return stderr_stream;
    
public java.io.InputStreamgetInputStream()

	return stdout_stream;
    
public java.io.OutputStreamgetOutputStream()

	return stdin_stream;
    
static java.lang.Processstart(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 intwaitFor()