Source for java.lang.Process

   1: /* Process.java - Represent spawned system process
   2:    Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005
   3:    Free Software Foundation, Inc.
   4: 
   5: This file is part of GNU Classpath.
   6: 
   7: GNU Classpath is free software; you can redistribute it and/or modify
   8: it under the terms of the GNU General Public License as published by
   9: the Free Software Foundation; either version 2, or (at your option)
  10: any later version.
  11: 
  12: GNU Classpath is distributed in the hope that it will be useful, but
  13: WITHOUT ANY WARRANTY; without even the implied warranty of
  14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15: General Public License for more details.
  16: 
  17: You should have received a copy of the GNU General Public License
  18: along with GNU Classpath; see the file COPYING.  If not, write to the
  19: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20: 02110-1301 USA.
  21: 
  22: Linking this library statically or dynamically with other modules is
  23: making a combined work based on this library.  Thus, the terms and
  24: conditions of the GNU General Public License cover the whole
  25: combination.
  26: 
  27: As a special exception, the copyright holders of this library give you
  28: permission to link this library with independent modules to produce an
  29: executable, regardless of the license terms of these independent
  30: modules, and to copy and distribute the resulting executable under
  31: terms of your choice, provided that you also meet, for each linked
  32: independent module, the terms and conditions of the license of that
  33: module.  An independent module is a module which is not derived from
  34: or based on this library.  If you modify this library, you may extend
  35: this exception to your version of the library, but you are not
  36: obligated to do so.  If you do not wish to do so, delete this
  37: exception statement from your version. */
  38: 
  39: 
  40: package java.lang;
  41: 
  42: import java.io.InputStream;
  43: import java.io.OutputStream;
  44: 
  45: /**
  46:  * An instance of a subclass of <code>Process</code> is created by the
  47:  * <code>Runtime.exec</code> methods.  Methods in <code>Process</code>
  48:  * provide a means to send input to a process, obtain the output from a
  49:  * subprocess, destroy a subprocess, obtain the exit value from a
  50:  * subprocess, and wait for a subprocess to complete.
  51:  *
  52:  * <p>This is dependent on the platform, and some processes (like native
  53:  * windowing processes, 16-bit processes in Windows, or shell scripts) may
  54:  * be limited in functionality. Because some platforms have limited buffers
  55:  * between processes, you may need to provide input and read output to prevent
  56:  * the process from blocking, or even deadlocking.
  57:  *
  58:  * <p>Even if all references to this object disapper, the process continues
  59:  * to execute to completion. There are no guarantees that the
  60:  * subprocess execute asynchronously or concurrently with the process which
  61:  * owns this object.
  62:  *
  63:  * @author Brian Jones
  64:  * @author Tom Tromey (tromey@cygnus.com)
  65:  * @see Runtime#exec(String[], String[], File)
  66:  * @since 1.0
  67:  * @status updated to 1.4
  68:  */
  69: public abstract class Process
  70: {
  71:   /**
  72:    * Empty constructor does nothing.
  73:    */
  74:   public Process()
  75:   {
  76:   }
  77: 
  78:   /**
  79:    * Obtain the output stream that sends data to the subprocess. This is
  80:    * the STDIN of the subprocess. When implementing, you should probably
  81:    * use a buffered stream.
  82:    *
  83:    * @return the output stream that pipes to the process input
  84:    */
  85:   public abstract OutputStream getOutputStream();
  86: 
  87:   /**
  88:    * Obtain the input stream that receives data from the subprocess. This is
  89:    * the STDOUT of the subprocess. When implementing, you should probably
  90:    * use a buffered stream.
  91:    *
  92:    * @return the input stream that pipes data from the process output
  93:    */
  94:   public abstract InputStream getInputStream();
  95: 
  96:   /**
  97:    * Obtain the input stream that receives data from the subprocess. This is
  98:    * the STDERR of the subprocess. When implementing, you should probably
  99:    * use a buffered stream.
 100:    *
 101:    * @return the input stream that pipes data from the process error output
 102:    */
 103:   public abstract InputStream getErrorStream();
 104: 
 105:   /**
 106:    * The thread calling <code>waitFor</code> will block until the subprocess
 107:    * has terminated. If the process has already terminated then the method
 108:    * immediately returns with the exit value of the subprocess.
 109:    *
 110:    * @return the subprocess exit value; 0 conventionally denotes success
 111:    * @throws InterruptedException if another thread interrupts the blocked one
 112:    */
 113:   public abstract int waitFor() throws InterruptedException;
 114: 
 115:   /**
 116:    * When a process terminates there is associated with that termination
 117:    * an exit value for the process to indicate why it terminated. A return
 118:    * of <code>0</code> denotes normal process termination by convention.
 119:    *
 120:    * @return the exit value of the subprocess
 121:    * @throws IllegalThreadStateException if the subprocess has not terminated
 122:    */
 123:   public abstract int exitValue();
 124: 
 125:   /**
 126:    * Kills the subprocess and all of its children forcibly.
 127:    */
 128:   public abstract void destroy();
 129: } // class Process