• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 
18 package java.lang;
19 
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 
23 /**
24  * Represents an external process. Enables writing to, reading from, destroying,
25  * and waiting for the external process, as well as querying its exit value.
26  *
27  * @see Runtime#exec
28  * @see ProcessBuilder#start()
29  */
30 public abstract class Process {
31 
32     /**
33      * Terminates this process and closes any associated streams.
34      */
destroy()35     abstract public void destroy();
36 
37     /**
38      * Returns the exit value of the native process represented by this object.
39      * It is available only when the native process has terminated.
40      *
41      * @return the exit value of this process.
42      * @throws IllegalThreadStateException
43      *             if this process has not terminated.
44      */
exitValue()45     abstract public int exitValue();
46 
47     /**
48      * Returns an input stream that is connected to the error stream
49      * <em>(stderr)</em> of the native process represented by this object.
50      *
51      * @return the input stream to read from the error stream associated with
52      *         the native process.
53      */
getErrorStream()54     abstract public InputStream getErrorStream();
55 
56     /**
57      * Returns an input stream that is connected to the standard output stream
58      * <em>(stdout)</em> of the native process represented by this object.
59      *
60      * @return the input stream to read from the output stream associated with
61      *         the native process.
62      */
getInputStream()63     abstract public InputStream getInputStream();
64 
65     /**
66      * Returns an output stream that is connected to the standard input stream
67      * <em>(stdin)</em> of the native process represented by this object.
68      *
69      * @return the output stream to write to the input stream associated with
70      *         the native process.
71      */
getOutputStream()72     abstract public OutputStream getOutputStream();
73 
74     /**
75      * Causes the calling thread to wait for the native process associated with
76      * this object to finish executing.
77      *
78      * @return the exit value of the native process being waited on.
79      * @throws InterruptedException
80      *             if the calling thread is interrupted.
81      */
waitFor()82     abstract public int waitFor() throws InterruptedException;
83 }
84