1. /*
  2. * @(#)Process.java 1.23 03/12/19
  3. *
  4. * Copyright 2004 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 {@link ProcessBuilder#start()} and
  11. * {@link Runtime#exec(String[],String[],File) Runtime.exec}
  12. * methods create a native process and
  13. * return an instance of a subclass of <code>Process</code> that can
  14. * be used to control the process and obtain information about it.
  15. * The class <code>Process</code> provides methods for performing
  16. * input from the process, performing output to the process, waiting
  17. * for the process to complete, checking the exit status of the process,
  18. * and destroying (killing) the process.
  19. *
  20. * <p>
  21. * The methods that create processes may not work well for special
  22. * processes on certain native platforms, such as native windowing
  23. * processes, daemon processes, Win16/DOS processes on Microsoft Windows, 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. * ({@link #getOutputStream()},
  28. * {@link #getInputStream()},
  29. * {@link #getErrorStream()}).
  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. *
  36. * <p>
  37. * The subprocess is not killed when there are no more references to
  38. * the <code>Process</code> object, but rather the subprocess
  39. * continues executing asynchronously.
  40. *
  41. * <p>
  42. * There is no requirement that a process represented by a <code>Process</code>
  43. * object execute asynchronously or concurrently with respect to the Java
  44. * process that owns the <code>Process</code> object.
  45. *
  46. * @author unascribed
  47. * @version 1.23, 12/19/03
  48. * @see ProcessBuilder
  49. * @see Runtime#exec(String[], String[], File)
  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. * @see ProcessBuilder#redirectErrorStream()
  77. */
  78. abstract public InputStream getInputStream();
  79. /**
  80. * Gets the error stream of the subprocess.
  81. * The stream obtains data piped from the error output stream of the
  82. * process represented by this <code>Process</code> object.
  83. * <p>
  84. * Implementation note: It is a good idea for the input stream to be
  85. * buffered.
  86. *
  87. * @return the input stream connected to the error stream of the
  88. * subprocess.
  89. * @see ProcessBuilder#redirectErrorStream()
  90. */
  91. abstract public InputStream getErrorStream();
  92. /**
  93. * causes the current thread to wait, if necessary, until the
  94. * process represented by this <code>Process</code> object has
  95. * terminated. This method returns
  96. * immediately if the subprocess has already terminated. If the
  97. * subprocess has not yet terminated, the calling thread will be
  98. * blocked until the subprocess exits.
  99. *
  100. * @return the exit value of the process. By convention,
  101. * <code>0</code> indicates normal termination.
  102. * @exception InterruptedException if the current thread is
  103. * {@link Thread#interrupt() interrupted} by another thread
  104. * while it is waiting, then the wait is ended and an
  105. * {@link InterruptedException} is thrown.
  106. */
  107. abstract public int waitFor() throws InterruptedException;
  108. /**
  109. * Returns the exit value for the subprocess.
  110. *
  111. * @return the exit value of the subprocess represented by this
  112. * <code>Process</code> object. by convention, the value
  113. * <code>0</code> indicates normal termination.
  114. * @exception IllegalThreadStateException if the subprocess represented
  115. * by this <code>Process</code> object has not yet terminated.
  116. */
  117. abstract public int exitValue();
  118. /**
  119. * Kills the subprocess. The subprocess represented by this
  120. * <code>Process</code> object is forcibly terminated.
  121. */
  122. abstract public void destroy();
  123. }