
- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java.lang.ProcessBuilder.redirectErrorStrestart() Method
Description
The java.lang.ProcessBuilder.start() method starts a new process using the attributes of this process builder. The new process will invoke the command and arguments given by command(), in a working directory as given by directory(), with a process environment as given by environment(). This method checks that the command is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty list of non-null strings.
If there is a security manager, its checkExec method is called with the first component of this object's command array as its argument. This may result in a SecurityException being thrown.
Declaration
Following is the declaration for java.lang.ProcessBuilder.start() method
public Process start()
Parameters
NA
Return Value
This method returns a new Process object for managing the subprocess
Exception
NullPointerException − If an element of the command list is null
IndexOutOfBoundsException − If the command is an empty list (has size 0)
SecurityException − If a security manager exists and its checkExec method doesn't allow creation of the subprocess
IOException − If an I/O error occurs
Example
The following example shows the usage of lang.ProcessBuilder.start() method.
Live Demopackage com.tutorialspoint; import java.io.IOException; public class ProcessBuilderDemo { public static void main(String[] args) { // create a new list of arguments for our process String[] list = {"notepad.exe", "test.txt"}; // create the process builder ProcessBuilder pb = new ProcessBuilder(list); try { // start the subprocess System.out.println("Starting the process.."); pb.start(); } catch (IOException ex) { ex.printStackTrace(); } } }
Let us compile and run the above program, this will produce the following result −
Starting the process..