java.lang
Class Process

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.lang.Process

public abstract class Process
extends Object sample code for java.lang.Object definition code for java.lang.Object

The ProcessBuilder.start() sample code for java.lang.ProcessBuilder.start() definition code for java.lang.ProcessBuilder.start() and Runtime.exec sample code for java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File) definition code for java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File) methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. The class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.

The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (getOutputStream() sample code for java.lang.Process.getOutputStream() definition code for java.lang.Process.getOutputStream() , getInputStream() sample code for java.lang.Process.getInputStream() definition code for java.lang.Process.getInputStream() , getErrorStream() sample code for java.lang.Process.getErrorStream() definition code for java.lang.Process.getErrorStream() ). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

The subprocess is not killed when there are no more references to the Process object, but rather the subprocess continues executing asynchronously.

There is no requirement that a process represented by a Process object execute asynchronously or concurrently with respect to the Java process that owns the Process object.

Since:
JDK1.0
See Also:
ProcessBuilder sample code for java.lang.ProcessBuilder definition code for java.lang.ProcessBuilder , Runtime.exec(String[], String[], File) sample code for java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File) definition code for java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File)

Constructor Summary
Process sample code for java.lang.Process.Process() definition code for java.lang.Process.Process() ()
           
 
Method Summary
abstract  void destroy sample code for java.lang.Process.destroy() definition code for java.lang.Process.destroy() ()
          Kills the subprocess.
abstract  int exitValue sample code for java.lang.Process.exitValue() definition code for java.lang.Process.exitValue() ()
          Returns the exit value for the subprocess.
abstract  InputStream sample code for java.io.InputStream definition code for java.io.InputStream getErrorStream sample code for java.lang.Process.getErrorStream() definition code for java.lang.Process.getErrorStream() ()
          Gets the error stream of the subprocess.
abstract  InputStream sample code for java.io.InputStream definition code for java.io.InputStream getInputStream sample code for java.lang.Process.getInputStream() definition code for java.lang.Process.getInputStream() ()
          Gets the input stream of the subprocess.
abstract  OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream getOutputStream sample code for java.lang.Process.getOutputStream() definition code for java.lang.Process.getOutputStream() ()
          Gets the output stream of the subprocess.
abstract  int waitFor sample code for java.lang.Process.waitFor() definition code for java.lang.Process.waitFor() ()
          causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

Process sample code for java.lang.Process() definition code for java.lang.Process()

public Process()
Method Detail

getOutputStream sample code for java.lang.Process.getOutputStream() definition code for java.lang.Process.getOutputStream()

public abstract OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  getOutputStream()
Gets the output stream of the subprocess. Output to the stream is piped into the standard input stream of the process represented by this Process object.

Implementation note: It is a good idea for the output stream to be buffered.

Returns:
the output stream connected to the normal input of the subprocess.

getInputStream sample code for java.lang.Process.getInputStream() definition code for java.lang.Process.getInputStream()

public abstract InputStream sample code for java.io.InputStream definition code for java.io.InputStream  getInputStream()
Gets the input stream of the subprocess. The stream obtains data piped from the standard output stream of the process represented by this Process object.

Implementation note: It is a good idea for the input stream to be buffered.

Returns:
the input stream connected to the normal output of the subprocess.
See Also:
ProcessBuilder.redirectErrorStream() sample code for java.lang.ProcessBuilder.redirectErrorStream() definition code for java.lang.ProcessBuilder.redirectErrorStream()

getErrorStream sample code for java.lang.Process.getErrorStream() definition code for java.lang.Process.getErrorStream()

public abstract InputStream sample code for java.io.InputStream definition code for java.io.InputStream  getErrorStream()
Gets the error stream of the subprocess. The stream obtains data piped from the error output stream of the process represented by this Process object.

Implementation note: It is a good idea for the input stream to be buffered.

Returns:
the input stream connected to the error stream of the subprocess.
See Also:
ProcessBuilder.redirectErrorStream() sample code for java.lang.ProcessBuilder.redirectErrorStream() definition code for java.lang.ProcessBuilder.redirectErrorStream()

waitFor sample code for java.lang.Process.waitFor() definition code for java.lang.Process.waitFor()

public abstract int waitFor()
                     throws InterruptedException sample code for java.lang.InterruptedException definition code for java.lang.InterruptedException 
causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits.

Returns:
the exit value of the process. By convention, 0 indicates normal termination.
Throws:
InterruptedException sample code for java.lang.InterruptedException definition code for java.lang.InterruptedException - if the current thread is interrupted sample code for java.lang.Thread.interrupt() definition code for java.lang.Thread.interrupt() by another thread while it is waiting, then the wait is ended and an InterruptedException sample code for java.lang.InterruptedException definition code for java.lang.InterruptedException is thrown.

exitValue sample code for java.lang.Process.exitValue() definition code for java.lang.Process.exitValue()

public abstract int exitValue()
Returns the exit value for the subprocess.

Returns:
the exit value of the subprocess represented by this Process object. by convention, the value 0 indicates normal termination.
Throws:
IllegalThreadStateException sample code for java.lang.IllegalThreadStateException definition code for java.lang.IllegalThreadStateException - if the subprocess represented by this Process object has not yet terminated.

destroy sample code for java.lang.Process.destroy() definition code for java.lang.Process.destroy()

public abstract void destroy()
Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.