1. /*
  2. * @(#)Process.java 1.17 00/02/02
  3. *
  4. * Copyright 1995-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.lang;
  11. import java.io.*;
  12. /**
  13. * The <code>Runtime.exec</code> methods create a native process and
  14. * return an instance of a subclass of <code>Process</code> that can
  15. * be used to control the process and obtain information about it.
  16. * The class <code>Process</code> provides methods for performing
  17. * input from the process, performing output to the process, waiting
  18. * for the process to complete, checking the exit status of the process,
  19. * and destroying (killing) the process.
  20. * <p>
  21. * The <code>Runtime.exec</code> methods may not work well for special
  22. * processes on certain native platforms, such as native windowing
  23. * processes, daemon processes, Win16/DOS processes on Win32, or shell
  24. * scripts. The created subprocess does not have its own terminal or
  25. * console. All its standard io (i.e. stdin, stdout, stderr) operations
  26. * will be redirected to the parent process through three streams
  27. * (<code>Process.getOutputStream()</code>,
  28. * <code>Process.getInputStream()</code>,
  29. * <code>Process.getErrorStream()</code>).
  30. * The parent process uses these streams to feed input to and get output
  31. * from the subprocess. Because some native platforms only provide
  32. * limited buffer size for standard input and output streams, failure
  33. * to promptly write the input stream or read the output stream of
  34. * the subprocess may cause the subprocess to block, and even deadlock.
  35. * <p>
  36. * The subprocess is not killed when there are no more references to
  37. * the <code>Process</code> object, but rather the subprocess
  38. * continues executing asynchronously.
  39. * <p>
  40. * There is no requirement that a process represented by a <code>Process</code>
  41. * object execute asynchronously or concurrently with respect to the Java
  42. * process that owns the <code>Process</code> object.
  43. *
  44. * @author unascribed
  45. * @version 1.17, 02/02/00
  46. * @see java.lang.Runtime#exec(java.lang.String)
  47. * @see java.lang.Runtime#exec(java.lang.String, java.lang.String[])
  48. * @see java.lang.Runtime#exec(java.lang.String[])
  49. * @see java.lang.Runtime#exec(java.lang.String[], java.lang.String[])
  50. * @since JDK1.0
  51. */
  52. public abstract class Process
  53. {
  54. /**
  55. * Gets the output stream of the subprocess.
  56. * Output to the stream is piped into the standard input stream of
  57. * the process represented by this <code>Process</code> object.
  58. * <p>
  59. * Implementation note: It is a good idea for the output stream to
  60. * be buffered.
  61. *
  62. * @return the output stream connected to the normal input of the
  63. * subprocess.
  64. */
  65. abstract public OutputStream getOutputStream();
  66. /**
  67. * Gets the input stream of the subprocess.
  68. * The stream obtains data piped from the standard output stream
  69. * of the process represented by this <code>Process</code> object.
  70. * <p>
  71. * Implementation note: It is a good idea for the input stream to
  72. * be buffered.
  73. *
  74. * @return the input stream connected to the normal output of the
  75. * subprocess.
  76. */
  77. abstract public InputStream getInputStream();
  78. /**
  79. * Gets the error stream of the subprocess.
  80. * The stream obtains data piped from the error output stream of the
  81. * process represented by this <code>Process</code> object.
  82. * <p>
  83. * Implementation note: It is a good idea for the input stream to be
  84. * buffered.
  85. *
  86. * @return the input stream connected to the error stream of the
  87. * subprocess.
  88. */
  89. abstract public InputStream getErrorStream();
  90. /**
  91. * causes the current thread to wait, if necessary, until the
  92. * process represented by this <code>Process</code> object has
  93. * terminated. This method returns
  94. * immediately if the subprocess has already terminated. If the
  95. * subprocess has not yet terminated, the calling thread will be
  96. * blocked until the subprocess exits.
  97. *
  98. * @return the exit value of the process. By convention,
  99. * <code>0</code> indicates normal termination.
  100. * @exception InterruptedException if the current thread is
  101. * {@link Thread#interrupt() interrupted} by another thread
  102. * while it is waiting, then the wait is ended and an
  103. * <code>InterruptedException</code> is thrown.
  104. */
  105. abstract public int waitFor() throws InterruptedException;
  106. /**
  107. * Returns the exit value for the subprocess.
  108. *
  109. * @return the exit value of the subprocess represented by this
  110. * <code>Process</code> object. by convention, the value
  111. * <code>0</code> indicates normal termination.
  112. * @exception IllegalThreadStateException if the subprocess represented
  113. * by this <code>Process</code> object has not yet terminated.
  114. */
  115. abstract public int exitValue();
  116. /**
  117. * Kills the subprocess. The subprocess represented by this
  118. * <code>Process</code> object is forcibly terminated.
  119. */
  120. abstract public void destroy();
  121. }