Java.lang.ProcessBuilder.command() Method
Advertisements
Description
The java.lang.ProcessBuilder.command() method returns this process builder's operating system program and arguments. The returned list is not a copy. Subsequent updates to the list will be reflected in the state of this process builder.
Declaration
Following is the declaration for java.lang.ProcessBuilder.command() method
public List<String> command()
Parameters
NA
Return Value
This method returns this process builder's program and its arguments
Exception
NA
Example
The following example shows the usage of lang.ProcessBuilder.command() method.
package com.tutorialspoint;
import java.util.ArrayList;
import java.util.List;
public class ProcessBuilderDemo {
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());
}
}
Let us compile and run the above program, this will produce the following result:
[notepad.exe]