Process.java 4.9 KB

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