📄 javalang.doc14.html
字号:
<html>
<head>
<title>The Java Language Specification The Package java.lang </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
<a href="index.html">Contents</a> | <a href="javalang.doc13.html">Prev</a> | <a href="javalang.doc15.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
<a name="14463"></a>
<center><h1>20.15 The Class <code>java.lang.Process</code></h1></center>
<a name="28945"></a>
The method <code>exec</code> <a href="javalang.doc15.html#14080">(§20.16.3)</a> of class <code>Runtime</code> returns a reference to a <code>Process</code>
object. The class <code>Process</code> provides methods for performing input from the process,
performing output to the process, waiting for the process to complete, checking
the exit status of the process, and destroying (killing) the process.
<p><a name="28951"></a>
Dropping the last reference to a <code>Process</code> instance, thus allowing the <code>Process</code> object to be reclaimed, does <i>not</i> automatically kill the associated process. <p>
<a name="29009"></a>
There is no requirement that a process represented by a <code>Process</code> object execute asynchronously or concurrently with respect to the Java process that owns the <code>Process</code> object.<p>
<pre><a name="14067"></a>
<a name="28957"></a>public abstract class <code><b>Process</b></code> {
<a name="3085"></a> public abstract OutputStream <code><b>getOutputStream</b></code>();
<a name="3086"></a> public abstract InputStream <code><b>getInputStream</b></code>();
<a name="3087"></a> public abstract InputStream <code><b>getErrorStream</b></code>();
<a name="3088"></a> public abstract int <code><b>waitFor</b></code>()<br>
throws InterruptedException;
<a name="3089"></a> public abstract int <code><b>exitValue</b></code>()<br>
throws <code>IllegalThreadStateException</code>;
<a name="3090"></a> public abstract void <code><b>destroy</b></code>();
<a name="3093"></a>}
</pre><a name="14068"></a>
<p><font size=+1><strong>20.15.1 </strong> <code>public abstract OutputStream <code><b>getOutputStream</b></code>()</code></font>
<p>
<a name="29022"></a>
This method returns an <code>OutputStream</code>. Output to the stream is piped into the
standard input stream of the process represented by this <code>Process</code> object.
<p><a name="29026"></a>
Implementation note: It is a good idea for the output stream to be buffered.<p>
<a name="14069"></a>
<p><font size=+1><strong>20.15.2 </strong> <code>public abstract InputStream <code><b>getInputStream</b></code>()</code></font>
<p>
<a name="29028"></a>
This method returns an <code>InputStream</code>. The stream obtains data piped from the
standard output stream of the process represented by this <code>Process</code> object.
<p><a name="29029"></a>
Implementation note: It is a good idea for the input stream to be buffered.<p>
<a name="14070"></a>
<p><font size=+1><strong>20.15.3 </strong> <code>public abstract InputStream <code><b>getErrorStream</b></code>()</code></font>
<p>
<a name="29063"></a>
This method returns an <code>InputStream</code>. The stream obtains data piped from the
error output stream of the process represented by this <code>Process</code> object.
<p><a name="29064"></a>
Implementation note: It is a good idea for the input stream to be buffered.<p>
<a name="14071"></a>
<p><font size=+1><strong>20.15.4 </strong> <code>public abstract int <code><b>waitFor</b></code>()<br>throws InterruptedException</code></font>
<p>
<a name="29070"></a>
This method causes the current thread to wait, if necessary, until the process represented
by this <code>Process</code> object has terminated. Then the exit value of the process
is returned. By convention, the value <code>0</code> indicates normal termination.
<p><a name="29173"></a>
If the current thread is interrupted <a href="javalang.doc18.html#29179">(§20.20.31)</a> by another thread while it is waiting, then the wait is ended and an <code>InterruptedException</code> is thrown.<p>
<a name="14073"></a>
<p><font size=+1><strong>20.15.5 </strong> <code>public abstract int <code><b>exitValue</b></code>()<br>throws IllegalThreadStateException</code></font>
<p>
<a name="29085"></a>
If the process represented by this <code>Process</code> object has not yet terminated, then an
<code>IllegalThreadStateException</code> is thrown. Otherwise, the exit value of the process
is returned. By convention, the value <code>0</code> indicates normal termination.
<p><a name="14074"></a>
<p><font size=+1><strong>20.15.6 </strong> <code>public abstract void <code><b>destroy</b></code>()</code></font>
<p>
<a name="36435"></a>
The process represented by this <code>Process</code> object is forcibly terminated.<img src="javalang.doc.anc50.gif">
<p><a name="29075"></a>
<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javalang.doc13.html">Prev</a> | <a href="javalang.doc15.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright © 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -