KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > Process


1 /*
2  * @(#)Process.java 1.23 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.lang;
9
10 import java.io.*;
11
12 /**
13  * The {@link ProcessBuilder#start()} and
14  * {@link Runtime#exec(String[],String[],File) Runtime.exec}
15  * methods create a native process and
16  * return an instance of a subclass of <code>Process</code> that can
17  * be used to control the process and obtain information about it.
18  * The class <code>Process</code> provides methods for performing
19  * input from the process, performing output to the process, waiting
20  * for the process to complete, checking the exit status of the process,
21  * and destroying (killing) the process.
22  *
23  * <p>
24  * The methods that create processes may not work well for special
25  * processes on certain native platforms, such as native windowing
26  * processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell
27  * scripts. The created subprocess does not have its own terminal or
28  * console. All its standard io (i.e. stdin, stdout, stderr) operations
29  * will be redirected to the parent process through three streams
30  * ({@link #getOutputStream()},
31  * {@link #getInputStream()},
32  * {@link #getErrorStream()}).
33  * The parent process uses these streams to feed input to and get output
34  * from the subprocess. Because some native platforms only provide
35  * limited buffer size for standard input and output streams, failure
36  * to promptly write the input stream or read the output stream of
37  * the subprocess may cause the subprocess to block, and even deadlock.
38  *
39  * <p>
40  * The subprocess is not killed when there are no more references to
41  * the <code>Process</code> object, but rather the subprocess
42  * continues executing asynchronously.
43  *
44  * <p>
45  * There is no requirement that a process represented by a <code>Process</code>
46  * object execute asynchronously or concurrently with respect to the Java
47  * process that owns the <code>Process</code> object.
48  *
49  * @author unascribed
50  * @version 1.23, 12/19/03
51  * @see ProcessBuilder
52  * @see Runtime#exec(String[], String[], File)
53  * @since JDK1.0
54  */

55 public abstract class Process
56 {
57     /**
58      * Gets the output stream of the subprocess.
59      * Output to the stream is piped into the standard input stream of
60      * the process represented by this <code>Process</code> object.
61      * <p>
62      * Implementation note: It is a good idea for the output stream to
63      * be buffered.
64      *
65      * @return the output stream connected to the normal input of the
66      * subprocess.
67      */

68     abstract public OutputStream getOutputStream();
69
70     /**
71      * Gets the input stream of the subprocess.
72      * The stream obtains data piped from the standard output stream
73      * of the process represented by this <code>Process</code> object.
74      * <p>
75      * Implementation note: It is a good idea for the input stream to
76      * be buffered.
77      *
78      * @return the input stream connected to the normal output of the
79      * subprocess.
80      * @see ProcessBuilder#redirectErrorStream()
81      */

82     abstract public InputStream getInputStream();
83
84     /**
85      * Gets the error stream of the subprocess.
86      * The stream obtains data piped from the error output stream of the
87      * process represented by this <code>Process</code> object.
88      * <p>
89      * Implementation note: It is a good idea for the input stream to be
90      * buffered.
91      *
92      * @return the input stream connected to the error stream of the
93      * subprocess.
94      * @see ProcessBuilder#redirectErrorStream()
95      */

96     abstract public InputStream getErrorStream();
97
98     /**
99      * causes the current thread to wait, if necessary, until the
100      * process represented by this <code>Process</code> object has
101      * terminated. This method returns
102      * immediately if the subprocess has already terminated. If the
103      * subprocess has not yet terminated, the calling thread will be
104      * blocked until the subprocess exits.
105      *
106      * @return the exit value of the process. By convention,
107      * <code>0</code> indicates normal termination.
108      * @exception InterruptedException if the current thread is
109      * {@link Thread#interrupt() interrupted} by another thread
110      * while it is waiting, then the wait is ended and an
111      * {@link InterruptedException} is thrown.
112      */

113     abstract public int waitFor() throws InterruptedException JavaDoc;
114
115     /**
116      * Returns the exit value for the subprocess.
117      *
118      * @return the exit value of the subprocess represented by this
119      * <code>Process</code> object. by convention, the value
120      * <code>0</code> indicates normal termination.
121      * @exception IllegalThreadStateException if the subprocess represented
122      * by this <code>Process</code> object has not yet terminated.
123      */

124     abstract public int exitValue();
125
126     /**
127      * Kills the subprocess. The subprocess represented by this
128      * <code>Process</code> object is forcibly terminated.
129      */

130     abstract public void destroy();
131 }
132
Popular Tags