ProcessBuilder To Make System Calls In Java

Chapter: Java I/O Last Updated: 19-08-2017 08:02:03 UTC

Program:

            /* ............... START ............... */
                
import java.util.ArrayList;
import java.util.List;

public class JavaProcessBuilder {
	public static void main(String[] args) {

		// create a new list of arguments for our process
		List list = new ArrayList();
		list.add("notepad.exe");

		// create the process builder
		ProcessBuilder pb = new ProcessBuilder(list);

		// get the command list
		System.out.println("" + pb.command());

	}
}
                /* ............... END ............... */
        

Output

[notepad.exe]

Notes:

  • The ProcessBuilder class is used to create operating system processes.
  • In java we use two classes, the Runtime class and the Process class. Exec method of the Runtime class to run the command as a separate process. Invoking the exec method returns a Process object for managing the subprocess. getInputStream() and getErrorStream() are the two methods of the Process object to read the normal output of the command, and the error output of the command.

Tags

ProcessBuilder To Make System Calls,Java

Similar Programs Chapter Last Updated
Hidden File Check In Java Example Java I/O 20-06-2016
FileWriter In Java Example Java I/O 21-07-2016
FileReader In Java Example Java I/O 21-07-2016
FileOutputStream In Java Example Java I/O 21-07-2016
FileInputStream In Java Example Java I/O 21-07-2016
DataOutputStream In Java Example Java I/O 21-07-2016
DataInputStream In Java Example Java I/O 21-07-2016
CharArrayWriter In Java Example Java I/O 13-04-2016
CharArrayReader In Java Example Java I/O 21-07-2016
ByteArrayOutputStream In Java Example Java I/O 21-07-2016
ByteArrayInputStream In Java Example Java I/O 21-07-2016
BufferedWriter In Java Example Java I/O 21-07-2016
BufferedReader In Java Example Java I/O 21-07-2016
BufferedOutputStream In Java Example Java I/O 21-07-2016
BufferedInputStream In Java Example Java I/O 21-07-2016

1