0N/A/*
2362N/A * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.lang;
0N/A
0N/Aimport java.io.*;
0N/A
0N/A/**
0N/A * The {@link ProcessBuilder#start()} and
0N/A * {@link Runtime#exec(String[],String[],File) Runtime.exec}
0N/A * methods create a native process and return an instance of a
0N/A * subclass of {@code Process} that can be used to control the process
0N/A * and obtain information about it. The class {@code Process}
0N/A * provides methods for performing input from the process, performing
0N/A * output to the process, waiting for the process to complete,
0N/A * checking the exit status of the process, and destroying (killing)
0N/A * the process.
0N/A *
0N/A * <p>The methods that create processes may not work well for special
0N/A * processes on certain native platforms, such as native windowing
0N/A * processes, daemon processes, Win16/DOS processes on Microsoft
25N/A * Windows, or shell scripts.
25N/A *
25N/A * <p>By default, the created subprocess does not have its own terminal
25N/A * or console. All its standard I/O (i.e. stdin, stdout, stderr)
25N/A * operations will be redirected to the parent process, where they can
25N/A * be accessed via the streams obtained using the methods
25N/A * {@link #getOutputStream()},
25N/A * {@link #getInputStream()}, and
25N/A * {@link #getErrorStream()}.
0N/A * The parent process uses these streams to feed input to and get output
0N/A * from the subprocess. Because some native platforms only provide
0N/A * limited buffer size for standard input and output streams, failure
0N/A * to promptly write the input stream or read the output stream of
25N/A * the subprocess may cause the subprocess to block, or even deadlock.
25N/A *
25N/A * <p>Where desired, <a href="ProcessBuilder.html#redirect-input">
25N/A * subprocess I/O can also be redirected</a>
25N/A * using methods of the {@link ProcessBuilder} class.
0N/A *
0N/A * <p>The subprocess is not killed when there are no more references to
0N/A * the {@code Process} object, but rather the subprocess
0N/A * continues executing asynchronously.
0N/A *
0N/A * <p>There is no requirement that a process represented by a {@code
0N/A * Process} object execute asynchronously or concurrently with respect
0N/A * to the Java process that owns the {@code Process} object.
0N/A *
25N/A * <p>As of 1.5, {@link ProcessBuilder#start()} is the preferred way
25N/A * to create a {@code Process}.
25N/A *
0N/A * @since JDK1.0
0N/A */
0N/Apublic abstract class Process {
0N/A /**
0N/A * Returns the output stream connected to the normal input of the
0N/A * subprocess. Output to the stream is piped into the standard
25N/A * input of the process represented by this {@code Process} object.
25N/A *
25N/A * <p>If the standard input of the subprocess has been redirected using
25N/A * {@link ProcessBuilder#redirectInput(Redirect)
25N/A * ProcessBuilder.redirectInput}
25N/A * then this method will return a
25N/A * <a href="ProcessBuilder.html#redirect-input">null output stream</a>.
0N/A *
0N/A * <p>Implementation note: It is a good idea for the returned
0N/A * output stream to be buffered.
0N/A *
0N/A * @return the output stream connected to the normal input of the
0N/A * subprocess
0N/A */
0N/A abstract public OutputStream getOutputStream();
0N/A
0N/A /**
0N/A * Returns the input stream connected to the normal output of the
0N/A * subprocess. The stream obtains data piped from the standard
25N/A * output of the process represented by this {@code Process} object.
25N/A *
25N/A * <p>If the standard output of the subprocess has been redirected using
25N/A * {@link ProcessBuilder#redirectOutput(Redirect)
25N/A * ProcessBuilder.redirectOutput}
25N/A * then this method will return a
25N/A * <a href="ProcessBuilder.html#redirect-output">null input stream</a>.
25N/A *
25N/A * <p>Otherwise, if the standard error of the subprocess has been
25N/A * redirected using
25N/A * {@link ProcessBuilder#redirectErrorStream(boolean)
25N/A * ProcessBuilder.redirectErrorStream}
25N/A * then the input stream returned by this method will receive the
25N/A * merged standard output and the standard error of the subprocess.
0N/A *
0N/A * <p>Implementation note: It is a good idea for the returned
0N/A * input stream to be buffered.
0N/A *
0N/A * @return the input stream connected to the normal output of the
0N/A * subprocess
0N/A */
0N/A abstract public InputStream getInputStream();
0N/A
0N/A /**
25N/A * Returns the input stream connected to the error output of the
25N/A * subprocess. The stream obtains data piped from the error output
25N/A * of the process represented by this {@code Process} object.
25N/A *
25N/A * <p>If the standard error of the subprocess has been redirected using
25N/A * {@link ProcessBuilder#redirectError(Redirect)
25N/A * ProcessBuilder.redirectError} or
25N/A * {@link ProcessBuilder#redirectErrorStream(boolean)
25N/A * ProcessBuilder.redirectErrorStream}
25N/A * then this method will return a
25N/A * <a href="ProcessBuilder.html#redirect-output">null input stream</a>.
0N/A *
0N/A * <p>Implementation note: It is a good idea for the returned
0N/A * input stream to be buffered.
0N/A *
25N/A * @return the input stream connected to the error output of
0N/A * the subprocess
0N/A */
0N/A abstract public InputStream getErrorStream();
0N/A
0N/A /**
0N/A * Causes the current thread to wait, if necessary, until the
0N/A * process represented by this {@code Process} object has
0N/A * terminated. This method returns immediately if the subprocess
0N/A * has already terminated. If the subprocess has not yet
0N/A * terminated, the calling thread will be blocked until the
0N/A * subprocess exits.
0N/A *
0N/A * @return the exit value of the subprocess represented by this
0N/A * {@code Process} object. By convention, the value
0N/A * {@code 0} indicates normal termination.
0N/A * @throws InterruptedException if the current thread is
0N/A * {@linkplain Thread#interrupt() interrupted} by another
0N/A * thread while it is waiting, then the wait is ended and
0N/A * an {@link InterruptedException} is thrown.
0N/A */
0N/A abstract public int waitFor() throws InterruptedException;
0N/A
0N/A /**
0N/A * Returns the exit value for the subprocess.
0N/A *
0N/A * @return the exit value of the subprocess represented by this
0N/A * {@code Process} object. By convention, the value
0N/A * {@code 0} indicates normal termination.
0N/A * @throws IllegalThreadStateException if the subprocess represented
0N/A * by this {@code Process} object has not yet terminated
0N/A */
0N/A abstract public int exitValue();
0N/A
0N/A /**
0N/A * Kills the subprocess. The subprocess represented by this
0N/A * {@code Process} object is forcibly terminated.
0N/A */
0N/A abstract public void destroy();
0N/A}