001 /* Process.java - Represent spawned system process 002 Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005 003 Free Software Foundation, Inc. 004 005 This file is part of GNU Classpath. 006 007 GNU Classpath is free software; you can redistribute it and/or modify 008 it under the terms of the GNU General Public License as published by 009 the Free Software Foundation; either version 2, or (at your option) 010 any later version. 011 012 GNU Classpath is distributed in the hope that it will be useful, but 013 WITHOUT ANY WARRANTY; without even the implied warranty of 014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 General Public License for more details. 016 017 You should have received a copy of the GNU General Public License 018 along with GNU Classpath; see the file COPYING. If not, write to the 019 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 020 02110-1301 USA. 021 022 Linking this library statically or dynamically with other modules is 023 making a combined work based on this library. Thus, the terms and 024 conditions of the GNU General Public License cover the whole 025 combination. 026 027 As a special exception, the copyright holders of this library give you 028 permission to link this library with independent modules to produce an 029 executable, regardless of the license terms of these independent 030 modules, and to copy and distribute the resulting executable under 031 terms of your choice, provided that you also meet, for each linked 032 independent module, the terms and conditions of the license of that 033 module. An independent module is a module which is not derived from 034 or based on this library. If you modify this library, you may extend 035 this exception to your version of the library, but you are not 036 obligated to do so. If you do not wish to do so, delete this 037 exception statement from your version. */ 038 039 040 package java.lang; 041 042 import java.io.File; 043 import java.io.InputStream; 044 import java.io.OutputStream; 045 046 /** 047 * An instance of a subclass of <code>Process</code> is created by the 048 * <code>Runtime.exec</code> methods. Methods in <code>Process</code> 049 * provide a means to send input to a process, obtain the output from a 050 * subprocess, destroy a subprocess, obtain the exit value from a 051 * subprocess, and wait for a subprocess to complete. 052 * 053 * <p>This is dependent on the platform, and some processes (like native 054 * windowing processes, 16-bit processes in Windows, or shell scripts) may 055 * be limited in functionality. Because some platforms have limited buffers 056 * between processes, you may need to provide input and read output to prevent 057 * the process from blocking, or even deadlocking. 058 * 059 * <p>Even if all references to this object disapper, the process continues 060 * to execute to completion. There are no guarantees that the 061 * subprocess execute asynchronously or concurrently with the process which 062 * owns this object. 063 * 064 * @author Brian Jones 065 * @author Tom Tromey (tromey@cygnus.com) 066 * @see Runtime#exec(String[], String[], File) 067 * @since 1.0 068 * @status updated to 1.4 069 */ 070 public abstract class Process 071 { 072 /** 073 * Empty constructor does nothing. 074 */ 075 public Process() 076 { 077 } 078 079 /** 080 * Obtain the output stream that sends data to the subprocess. This is 081 * the STDIN of the subprocess. When implementing, you should probably 082 * use a buffered stream. 083 * 084 * @return the output stream that pipes to the process input 085 */ 086 public abstract OutputStream getOutputStream(); 087 088 /** 089 * Obtain the input stream that receives data from the subprocess. This is 090 * the STDOUT of the subprocess. When implementing, you should probably 091 * use a buffered stream. 092 * 093 * @return the input stream that pipes data from the process output 094 */ 095 public abstract InputStream getInputStream(); 096 097 /** 098 * Obtain the input stream that receives data from the subprocess. This is 099 * the STDERR of the subprocess. When implementing, you should probably 100 * use a buffered stream. 101 * 102 * @return the input stream that pipes data from the process error output 103 */ 104 public abstract InputStream getErrorStream(); 105 106 /** 107 * The thread calling <code>waitFor</code> will block until the subprocess 108 * has terminated. If the process has already terminated then the method 109 * immediately returns with the exit value of the subprocess. 110 * 111 * @return the subprocess exit value; 0 conventionally denotes success 112 * @throws InterruptedException if another thread interrupts the blocked one 113 */ 114 public abstract int waitFor() throws InterruptedException; 115 116 /** 117 * When a process terminates there is associated with that termination 118 * an exit value for the process to indicate why it terminated. A return 119 * of <code>0</code> denotes normal process termination by convention. 120 * 121 * @return the exit value of the subprocess 122 * @throws IllegalThreadStateException if the subprocess has not terminated 123 */ 124 public abstract int exitValue(); 125 126 /** 127 * Kills the subprocess and all of its children forcibly. 128 */ 129 public abstract void destroy(); 130 } // class Process