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