Java.lang.ProcessBuilder.command() Method
Advertisements
Description
The java.lang.ProcessBuilder.command(String... command) method Sets this process builder's operating system program and arguments. This is a convenience method that sets the command to a string list containing the same strings as the command array, in the same order. It is not checked whether command corresponds to a valid operating system command.
Declaration
Following is the declaration for java.lang.ProcessBuilder.command() method
public ProcessBuilder command(String... command)
Parameters
command -- A string array containing the program and its arguments
Return Value
This method returns this process builder
Exception
NA
Example
The following example shows the usage of lang.ProcessBuilder.command() method.
package com.tutorialspoint;
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);
// set the command list
pb.command(list);
// print the new command list
System.out.println("" + pb.command());
}
}
Let us compile and run the above program, this will produce the following result:
[notepad.exe, text.txt]