1 |
771 |
jeremybenn |
/* Process.java - Represent spawned system process
|
2 |
|
|
Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005
|
3 |
|
|
Free Software Foundation, Inc.
|
4 |
|
|
|
5 |
|
|
This file is part of GNU Classpath.
|
6 |
|
|
|
7 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
8 |
|
|
it under the terms of the GNU General Public License as published by
|
9 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
10 |
|
|
any later version.
|
11 |
|
|
|
12 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
13 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 |
|
|
General Public License for more details.
|
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License
|
18 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
19 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
20 |
|
|
02110-1301 USA.
|
21 |
|
|
|
22 |
|
|
Linking this library statically or dynamically with other modules is
|
23 |
|
|
making a combined work based on this library. Thus, the terms and
|
24 |
|
|
conditions of the GNU General Public License cover the whole
|
25 |
|
|
combination.
|
26 |
|
|
|
27 |
|
|
As a special exception, the copyright holders of this library give you
|
28 |
|
|
permission to link this library with independent modules to produce an
|
29 |
|
|
executable, regardless of the license terms of these independent
|
30 |
|
|
modules, and to copy and distribute the resulting executable under
|
31 |
|
|
terms of your choice, provided that you also meet, for each linked
|
32 |
|
|
independent module, the terms and conditions of the license of that
|
33 |
|
|
module. An independent module is a module which is not derived from
|
34 |
|
|
or based on this library. If you modify this library, you may extend
|
35 |
|
|
this exception to your version of the library, but you are not
|
36 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
37 |
|
|
exception statement from your version. */
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
package java.lang;
|
41 |
|
|
|
42 |
|
|
import java.io.File;
|
43 |
|
|
import java.io.InputStream;
|
44 |
|
|
import java.io.OutputStream;
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* An instance of a subclass of <code>Process</code> is created by the
|
48 |
|
|
* <code>Runtime.exec</code> methods. Methods in <code>Process</code>
|
49 |
|
|
* provide a means to send input to a process, obtain the output from a
|
50 |
|
|
* subprocess, destroy a subprocess, obtain the exit value from a
|
51 |
|
|
* subprocess, and wait for a subprocess to complete.
|
52 |
|
|
*
|
53 |
|
|
* <p>This is dependent on the platform, and some processes (like native
|
54 |
|
|
* windowing processes, 16-bit processes in Windows, or shell scripts) may
|
55 |
|
|
* be limited in functionality. Because some platforms have limited buffers
|
56 |
|
|
* between processes, you may need to provide input and read output to prevent
|
57 |
|
|
* the process from blocking, or even deadlocking.
|
58 |
|
|
*
|
59 |
|
|
* <p>Even if all references to this object disapper, the process continues
|
60 |
|
|
* to execute to completion. There are no guarantees that the
|
61 |
|
|
* subprocess execute asynchronously or concurrently with the process which
|
62 |
|
|
* owns this object.
|
63 |
|
|
*
|
64 |
|
|
* @author Brian Jones
|
65 |
|
|
* @author Tom Tromey (tromey@cygnus.com)
|
66 |
|
|
* @see Runtime#exec(String[], String[], File)
|
67 |
|
|
* @since 1.0
|
68 |
|
|
* @status updated to 1.4
|
69 |
|
|
*/
|
70 |
|
|
public abstract class Process
|
71 |
|
|
{
|
72 |
|
|
/**
|
73 |
|
|
* Empty constructor does nothing.
|
74 |
|
|
*/
|
75 |
|
|
public Process()
|
76 |
|
|
{
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Obtain the output stream that sends data to the subprocess. This is
|
81 |
|
|
* the STDIN of the subprocess. When implementing, you should probably
|
82 |
|
|
* use a buffered stream.
|
83 |
|
|
*
|
84 |
|
|
* @return the output stream that pipes to the process input
|
85 |
|
|
*/
|
86 |
|
|
public abstract OutputStream getOutputStream();
|
87 |
|
|
|
88 |
|
|
/**
|
89 |
|
|
* Obtain the input stream that receives data from the subprocess. This is
|
90 |
|
|
* the STDOUT of the subprocess. When implementing, you should probably
|
91 |
|
|
* use a buffered stream.
|
92 |
|
|
*
|
93 |
|
|
* @return the input stream that pipes data from the process output
|
94 |
|
|
*/
|
95 |
|
|
public abstract InputStream getInputStream();
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Obtain the input stream that receives data from the subprocess. This is
|
99 |
|
|
* the STDERR of the subprocess. When implementing, you should probably
|
100 |
|
|
* use a buffered stream.
|
101 |
|
|
*
|
102 |
|
|
* @return the input stream that pipes data from the process error output
|
103 |
|
|
*/
|
104 |
|
|
public abstract InputStream getErrorStream();
|
105 |
|
|
|
106 |
|
|
/**
|
107 |
|
|
* The thread calling <code>waitFor</code> will block until the subprocess
|
108 |
|
|
* has terminated. If the process has already terminated then the method
|
109 |
|
|
* immediately returns with the exit value of the subprocess.
|
110 |
|
|
*
|
111 |
|
|
* @return the subprocess exit value; 0 conventionally denotes success
|
112 |
|
|
* @throws InterruptedException if another thread interrupts the blocked one
|
113 |
|
|
*/
|
114 |
|
|
public abstract int waitFor() throws InterruptedException;
|
115 |
|
|
|
116 |
|
|
/**
|
117 |
|
|
* When a process terminates there is associated with that termination
|
118 |
|
|
* an exit value for the process to indicate why it terminated. A return
|
119 |
|
|
* of <code>0</code> denotes normal process termination by convention.
|
120 |
|
|
*
|
121 |
|
|
* @return the exit value of the subprocess
|
122 |
|
|
* @throws IllegalThreadStateException if the subprocess has not terminated
|
123 |
|
|
*/
|
124 |
|
|
public abstract int exitValue();
|
125 |
|
|
|
126 |
|
|
/**
|
127 |
|
|
* Kills the subprocess and all of its children forcibly.
|
128 |
|
|
*/
|
129 |
|
|
public abstract void destroy();
|
130 |
|
|
} // class Process
|