jdk/src/share/classes/java/lang/Process.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 48 dc5744ca15ea
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1995-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The {@link ProcessBuilder#start()} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * {@link Runtime#exec(String[],String[],File) Runtime.exec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * methods create a native process and return an instance of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * subclass of {@code Process} that can be used to control the process
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * and obtain information about it.  The class {@code Process}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * provides methods for performing input from the process, performing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * output to the process, waiting for the process to complete,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * checking the exit status of the process, and destroying (killing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>The methods that create processes may not work well for special
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * processes on certain native platforms, such as native windowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * processes, daemon processes, Win16/DOS processes on Microsoft
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Windows, or shell scripts.  The created subprocess does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * its own terminal or console.  All its standard I/O (i.e. stdin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * stdout, stderr) operations will be redirected to the parent process
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * through three streams
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * ({@link #getOutputStream()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * {@link #getInputStream()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * {@link #getErrorStream()}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The parent process uses these streams to feed input to and get output
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * from the subprocess.  Because some native platforms only provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * limited buffer size for standard input and output streams, failure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * to promptly write the input stream or read the output stream of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the subprocess may cause the subprocess to block, and even deadlock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>The subprocess is not killed when there are no more references to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * the {@code Process} object, but rather the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * continues executing asynchronously.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>There is no requirement that a process represented by a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Process} object execute asynchronously or concurrently with respect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * to the Java process that owns the {@code Process} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public abstract class Process {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Returns the output stream connected to the normal input of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * subprocess.  Output to the stream is piped into the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * input stream of the process represented by this {@code Process}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <p>Implementation note: It is a good idea for the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * output stream to be buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return the output stream connected to the normal input of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *         subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    abstract public OutputStream getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Returns the input stream connected to the normal output of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * subprocess.  The stream obtains data piped from the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * output stream of the process represented by this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Process} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * <p>Implementation note: It is a good idea for the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * input stream to be buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @return the input stream connected to the normal output of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *         subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see ProcessBuilder#redirectErrorStream()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    abstract public InputStream getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Returns the input stream connected to the error output stream of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * the subprocess.  The stream obtains data piped from the error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * output stream of the process represented by this {@code Process}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <p>Implementation note: It is a good idea for the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * input stream to be buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @return the input stream connected to the error output stream of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *         the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see ProcessBuilder#redirectErrorStream()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    abstract public InputStream getErrorStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Causes the current thread to wait, if necessary, until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * process represented by this {@code Process} object has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * terminated.  This method returns immediately if the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * has already terminated.  If the subprocess has not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * terminated, the calling thread will be blocked until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * subprocess exits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return the exit value of the subprocess represented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *         {@code Process} object.  By convention, the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *         {@code 0} indicates normal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @throws InterruptedException if the current thread is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *         {@linkplain Thread#interrupt() interrupted} by another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *         thread while it is waiting, then the wait is ended and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *         an {@link InterruptedException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    abstract public int waitFor() throws InterruptedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Returns the exit value for the subprocess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @return the exit value of the subprocess represented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *         {@code Process} object.  By convention, the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *         {@code 0} indicates normal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @throws IllegalThreadStateException if the subprocess represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *         by this {@code Process} object has not yet terminated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    abstract public int exitValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Kills the subprocess. The subprocess represented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * {@code Process} object is forcibly terminated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    abstract public void destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}