java.lang.ProcessBuilder command(List<String> command)


This java example source code demonstrates the use of command(List<String> command) method of ProcessBuilder class.

Some takeaways on this method:

  • This method sets this process builder’s operating system program and argument.
  • This method does not make a copy of the command list. Subsequent updates to the list will be reflected in the state of the process builder.
  • It is not checked whether command corresponds to a valid operating system command.
  • NullPointerException can be thrown by this method if the argument is null.

Method Syntax

public ProcessBuilder command(List<String> command)

Method Argument

Data Type Parameter Description
List<String> command the list containing the program and its arguments

Method Returns

The command(List<String> command) method returns this ProcessBuilder.


Requires Java 1.5 and up

Java ProcessBuilder command(List<String> command) Example

Below is a java code demonstrates the use of command(List<String> command) method of ProcessBuilder class.

Sample Output

Below is the sample output when you run the above example.

ProcessBuilder command(List command) method example