src/share/classes/java/lang/Process.java

Print this page




  74  * @since   JDK1.0
  75  */
  76 public abstract class Process {
  77     /**
  78      * Returns the output stream connected to the normal input of the
  79      * subprocess.  Output to the stream is piped into the standard
  80      * input of the process represented by this {@code Process} object.
  81      *
  82      * <p>If the standard input of the subprocess has been redirected using
  83      * {@link ProcessBuilder#redirectInput(Redirect)
  84      * ProcessBuilder.redirectInput}
  85      * then this method will return a
  86      * <a href="ProcessBuilder.html#redirect-input">null output stream</a>.
  87      *
  88      * <p>Implementation note: It is a good idea for the returned
  89      * output stream to be buffered.
  90      *
  91      * @return the output stream connected to the normal input of the
  92      *         subprocess
  93      */
  94     abstract public OutputStream getOutputStream();
  95 
  96     /**
  97      * Returns the input stream connected to the normal output of the
  98      * subprocess.  The stream obtains data piped from the standard
  99      * output of the process represented by this {@code Process} object.
 100      *
 101      * <p>If the standard output of the subprocess has been redirected using
 102      * {@link ProcessBuilder#redirectOutput(Redirect)
 103      * ProcessBuilder.redirectOutput}
 104      * then this method will return a
 105      * <a href="ProcessBuilder.html#redirect-output">null input stream</a>.
 106      *
 107      * <p>Otherwise, if the standard error of the subprocess has been
 108      * redirected using
 109      * {@link ProcessBuilder#redirectErrorStream(boolean)
 110      * ProcessBuilder.redirectErrorStream}
 111      * then the input stream returned by this method will receive the
 112      * merged standard output and the standard error of the subprocess.
 113      *
 114      * <p>Implementation note: It is a good idea for the returned
 115      * input stream to be buffered.
 116      *
 117      * @return the input stream connected to the normal output of the
 118      *         subprocess
 119      */
 120     abstract public InputStream getInputStream();
 121 
 122     /**
 123      * Returns the input stream connected to the error output of the
 124      * subprocess.  The stream obtains data piped from the error output
 125      * of the process represented by this {@code Process} object.
 126      *
 127      * <p>If the standard error of the subprocess has been redirected using
 128      * {@link ProcessBuilder#redirectError(Redirect)
 129      * ProcessBuilder.redirectError} or
 130      * {@link ProcessBuilder#redirectErrorStream(boolean)
 131      * ProcessBuilder.redirectErrorStream}
 132      * then this method will return a
 133      * <a href="ProcessBuilder.html#redirect-output">null input stream</a>.
 134      *
 135      * <p>Implementation note: It is a good idea for the returned
 136      * input stream to be buffered.
 137      *
 138      * @return the input stream connected to the error output of
 139      *         the subprocess
 140      */
 141     abstract public InputStream getErrorStream();
 142 
 143     /**
 144      * Causes the current thread to wait, if necessary, until the
 145      * process represented by this {@code Process} object has
 146      * terminated.  This method returns immediately if the subprocess
 147      * has already terminated.  If the subprocess has not yet
 148      * terminated, the calling thread will be blocked until the
 149      * subprocess exits.
 150      *
 151      * @return the exit value of the subprocess represented by this
 152      *         {@code Process} object.  By convention, the value
 153      *         {@code 0} indicates normal termination.
 154      * @throws InterruptedException if the current thread is
 155      *         {@linkplain Thread#interrupt() interrupted} by another
 156      *         thread while it is waiting, then the wait is ended and
 157      *         an {@link InterruptedException} is thrown.
 158      */
 159     abstract public int waitFor() throws InterruptedException;
 160 
 161     /**
 162      * Returns the exit value for the subprocess.
 163      *
 164      * @return the exit value of the subprocess represented by this
 165      *         {@code Process} object.  By convention, the value
 166      *         {@code 0} indicates normal termination.
 167      * @throws IllegalThreadStateException if the subprocess represented
 168      *         by this {@code Process} object has not yet terminated
 169      */
 170     abstract public int exitValue();
 171 
 172     /**







 173      * Kills the subprocess. The subprocess represented by this
 174      * {@code Process} object is forcibly terminated.
 175      */
 176     abstract public void destroy();








 177 }


  74  * @since   JDK1.0
  75  */
  76 public abstract class Process {
  77     /**
  78      * Returns the output stream connected to the normal input of the
  79      * subprocess.  Output to the stream is piped into the standard
  80      * input of the process represented by this {@code Process} object.
  81      *
  82      * <p>If the standard input of the subprocess has been redirected using
  83      * {@link ProcessBuilder#redirectInput(Redirect)
  84      * ProcessBuilder.redirectInput}
  85      * then this method will return a
  86      * <a href="ProcessBuilder.html#redirect-input">null output stream</a>.
  87      *
  88      * <p>Implementation note: It is a good idea for the returned
  89      * output stream to be buffered.
  90      *
  91      * @return the output stream connected to the normal input of the
  92      *         subprocess
  93      */
  94     public abstract OutputStream getOutputStream();
  95 
  96     /**
  97      * Returns the input stream connected to the normal output of the
  98      * subprocess.  The stream obtains data piped from the standard
  99      * output of the process represented by this {@code Process} object.
 100      *
 101      * <p>If the standard output of the subprocess has been redirected using
 102      * {@link ProcessBuilder#redirectOutput(Redirect)
 103      * ProcessBuilder.redirectOutput}
 104      * then this method will return a
 105      * <a href="ProcessBuilder.html#redirect-output">null input stream</a>.
 106      *
 107      * <p>Otherwise, if the standard error of the subprocess has been
 108      * redirected using
 109      * {@link ProcessBuilder#redirectErrorStream(boolean)
 110      * ProcessBuilder.redirectErrorStream}
 111      * then the input stream returned by this method will receive the
 112      * merged standard output and the standard error of the subprocess.
 113      *
 114      * <p>Implementation note: It is a good idea for the returned
 115      * input stream to be buffered.
 116      *
 117      * @return the input stream connected to the normal output of the
 118      *         subprocess
 119      */
 120     public abstract InputStream getInputStream();
 121 
 122     /**
 123      * Returns the input stream connected to the error output of the
 124      * subprocess.  The stream obtains data piped from the error output
 125      * of the process represented by this {@code Process} object.
 126      *
 127      * <p>If the standard error of the subprocess has been redirected using
 128      * {@link ProcessBuilder#redirectError(Redirect)
 129      * ProcessBuilder.redirectError} or
 130      * {@link ProcessBuilder#redirectErrorStream(boolean)
 131      * ProcessBuilder.redirectErrorStream}
 132      * then this method will return a
 133      * <a href="ProcessBuilder.html#redirect-output">null input stream</a>.
 134      *
 135      * <p>Implementation note: It is a good idea for the returned
 136      * input stream to be buffered.
 137      *
 138      * @return the input stream connected to the error output of
 139      *         the subprocess
 140      */
 141     public abstract InputStream getErrorStream();
 142 
 143     /**
 144      * Causes the current thread to wait, if necessary, until the
 145      * process represented by this {@code Process} object has
 146      * terminated.  This method returns immediately if the subprocess
 147      * has already terminated.  If the subprocess has not yet
 148      * terminated, the calling thread will be blocked until the
 149      * subprocess exits.
 150      *
 151      * @return the exit value of the subprocess represented by this
 152      *         {@code Process} object.  By convention, the value
 153      *         {@code 0} indicates normal termination.
 154      * @throws InterruptedException if the current thread is
 155      *         {@linkplain Thread#interrupt() interrupted} by another
 156      *         thread while it is waiting, then the wait is ended and
 157      *         an {@link InterruptedException} is thrown.
 158      */
 159     public abstract int waitFor() throws InterruptedException;
 160 
 161     /**
 162      * Returns the exit value for the subprocess.
 163      *
 164      * @return the exit value of the subprocess represented by this
 165      *         {@code Process} object.  By convention, the value
 166      *         {@code 0} indicates normal termination.
 167      * @throws IllegalThreadStateException if the subprocess represented
 168      *         by this {@code Process} object has not yet terminated
 169      */
 170     public abstract int exitValue();
 171 
 172     /**
 173      * Kills the subprocess. Whether the subprocess represented by this
 174      * {@code Process} object is forcibly terminated or not is 
 175      * implementation dependent.
 176      */
 177     public abstract void destroy();
 178 
 179     /**
 180      * Kills the subprocess. The subprocess represented by this
 181      * {@code Process} object is forcibly terminated.
 182      */
 183     public abstract Process destroyForcibly();
 184 
 185     /**
 186      * Returns a boolean indicating whether the subprocess is alive.
 187      *
 188      * @return {@code true} if the subprocess represented by this
 189      *         {@code Process} object has not yet terminated.
 190      */
 191     public abstract boolean isAlive();
 192 }