001: /*
002: * @(#)Process.java 1.26 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.lang;
029:
030: import java.io.*;
031:
032: /**
033: * The <code>Runtime.exec</code> methods create a native process and
034: * return an instance of a subclass of <code>Process</code> that can
035: * be used to control the process and obtain information about it.
036: * The class <code>Process</code> provides methods for performing
037: * input from the process, performing output to the process, waiting
038: * for the process to complete, checking the exit status of the process,
039: * and destroying (killing) the process.
040: * <p>
041: * The <code>Runtime.exec</code> methods may not work well for special
042: * processes on certain native platforms, such as native windowing
043: * processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell
044: * scripts. The created subprocess does not have its own terminal or
045: * console. All its standard io (i.e. stdin, stdout, stderr) operations
046: * will be redirected to the parent process through three streams
047: * (<code>Process.getOutputStream()</code>,
048: * <code>Process.getInputStream()</code>,
049: * <code>Process.getErrorStream()</code>).
050: * The parent process uses these streams to feed input to and get output
051: * from the subprocess. Because some native platforms only provide
052: * limited buffer size for standard input and output streams, failure
053: * to promptly write the input stream or read the output stream of
054: * the subprocess may cause the subprocess to block, and even deadlock.
055: * <p>
056: * The subprocess is not killed when there are no more references to
057: * the <code>Process</code> object, but rather the subprocess
058: * continues executing asynchronously.
059: * <p>
060: * There is no requirement that a process represented by a <code>Process</code>
061: * object execute asynchronously or concurrently with respect to the Java
062: * process that owns the <code>Process</code> object.
063: *
064: * @author unascribed
065: * @version 1.17, 02/02/00
066: * @see java.lang.Runtime#exec(java.lang.String)
067: * @see java.lang.Runtime#exec(java.lang.String, java.lang.String[])
068: * @see java.lang.Runtime#exec(java.lang.String[])
069: * @see java.lang.Runtime#exec(java.lang.String[], java.lang.String[])
070: * @since JDK1.0
071: */
072: public abstract class Process {
073: /**
074: * Gets the output stream of the subprocess.
075: * Output to the stream is piped into the standard input stream of
076: * the process represented by this <code>Process</code> object.
077: * <p>
078: * Implementation note: It is a good idea for the output stream to
079: * be buffered.
080: *
081: * @return the output stream connected to the normal input of the
082: * subprocess.
083: */
084: abstract public OutputStream getOutputStream();
085:
086: /**
087: * Gets the input stream of the subprocess.
088: * The stream obtains data piped from the standard output stream
089: * of the process represented by this <code>Process</code> object.
090: * <p>
091: * Implementation note: It is a good idea for the input stream to
092: * be buffered.
093: *
094: * @return the input stream connected to the normal output of the
095: * subprocess.
096: */
097: abstract public InputStream getInputStream();
098:
099: /**
100: * Gets the error stream of the subprocess.
101: * The stream obtains data piped from the error output stream of the
102: * process represented by this <code>Process</code> object.
103: * <p>
104: * Implementation note: It is a good idea for the input stream to be
105: * buffered.
106: *
107: * @return the input stream connected to the error stream of the
108: * subprocess.
109: */
110: abstract public InputStream getErrorStream();
111:
112: /**
113: * causes the current thread to wait, if necessary, until the
114: * process represented by this <code>Process</code> object has
115: * terminated. This method returns
116: * immediately if the subprocess has already terminated. If the
117: * subprocess has not yet terminated, the calling thread will be
118: * blocked until the subprocess exits.
119: *
120: * @return the exit value of the process. By convention,
121: * <code>0</code> indicates normal termination.
122: * @exception InterruptedException if the current thread is
123: * {@link Thread#interrupt() interrupted} by another thread
124: * while it is waiting, then the wait is ended and an
125: * <code>InterruptedException</code> is thrown.
126: */
127: abstract public int waitFor() throws InterruptedException;
128:
129: /**
130: * Returns the exit value for the subprocess.
131: *
132: * @return the exit value of the subprocess represented by this
133: * <code>Process</code> object. by convention, the value
134: * <code>0</code> indicates normal termination.
135: * @exception IllegalThreadStateException if the subprocess represented
136: * by this <code>Process</code> object has not yet terminated.
137: */
138: abstract public int exitValue();
139:
140: /**
141: * Kills the subprocess. The subprocess represented by this
142: * <code>Process</code> object is forcibly terminated.
143: */
144: abstract public void destroy();
145: }
|