Process and processbuilder in Java

Source: Internet
Author: User

Java processbuilder is a final class.
Public final class processbuilderextends object is used to create operating system processes.
Each processbuilder instance manages a process property set. The START () method uses these attributes to create a new process instance. The START () method can be called repeatedly from the same instance to create a new sub-process with the same or related attributes.

 

 

Java. Lang
Process
Java. Lang. Object
Java. Lang. Process
--------------------------------------------------------------------------------
The public abstract class processextends objectprocessbuilder. Start () and runtime.exe C methods create a local process and return an instance of the Process subclass. This instance can be used to control the process and obtain relevant information. The process class provides methods to execute processes from process input, execution output to process, wait for the process to complete, check the exit status of the process, and destroy (kill) the process.
The Process Creation method may not work well for certain processes on the local platform, such as Windows processes, Daemon Processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created sub-process does not have its own terminal or console. All of its standard io (namely stdin, stdout, and stderr) operations will be redirected to the parent process through three streams (getoutputstream (), getinputstream (), and geterrorstream. The parent process uses these streams to provide the input to the child process and obtain the output from the child process. Some local platforms only provide limited Buffer Sizes for standard input and output streams. If the output stream or input stream of the read/write sub-process fails rapidly, the sub-process may be blocked, A deadlock even occurs.
When there is no more reference to the process object, instead of deleting the sub-process, the sub-process will continue to be executed asynchronously.
For Java processes with process objects, there is no need to execute processes represented by process objects asynchronously or concurrently.

 

Example:

Public class processtest {
Public static void main (string [] ARGs)
{
Try {
Processbuilder Pb = new processbuilder ("notepad.exe ");
PB. redirecterrorstream (true );
PROCESS p = Pb. Start ();
} Catch (exception E)
{
System. Out. Print (E. tostring ());
}
}
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.