GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.tutorialspoint.com — Java ProcessBuilder command() Method
Selected Reading
Java ProcessBuilder command() MethodDescriptionThe Java 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. DeclarationFollowing is the declaration for java.lang.ProcessBuilder.command() method public ProcessBuilder command(String... command) Parameterscommand − A string array containing the program and its arguments Return ValueThis method returns this process builder ExceptionNA Getting list of process for Notepad from a Process Builder ExampleThe following example shows the usage of ProcessBuilder command() method. In this program, we've created a list of Strings and added notepad.exe and text.txt to it. Using that list, we've initialized a ProcessBuilder instance. Using command(list) method, we've added a list to the ProcessBuilder. Then we've printed the underlying operating system command name and other details. 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());
}
}
OutputLet us compile and run the above program, this will produce the following result − [notepad.exe, test.txt] Getting list of process for Calculator from a Process Builder ExampleThe following example shows the usage of ProcessBuilder command() method. In this program, we've created a list of Strings and added calc.exe to it. Using that list, we've initialized a ProcessBuilder instance. Using command(list) method, we've added a list to the ProcessBuilder. Then we've printed the underlying operating system command name and other details. package com.tutorialspoint;
public class ProcessBuilderDemo {
public static void main(String[] args) {
// create a new list of arguments for our process
String[] list = {"calc.exe"};
// 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());
}
}
OutputLet us compile and run the above program, this will produce the following result − [calc.exe] Getting list of process for Explorer from a Process Builder ExampleThe following example shows the usage of ProcessBuilder command() method. In this program, we've created a list of Strings and added explorer.exe to it. Using that list, we've initialized a ProcessBuilder instance. Using command(list) method, we've added a list to the ProcessBuilder. Then we've printed the underlying operating system command name and other details. package com.tutorialspoint;
public class ProcessBuilderDemo {
public static void main(String[] args) {
// create a new list of arguments for our process
String[] list = {"explorer.exe"};
// 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());
}
}
OutputLet us compile and run the above program, this will produce the following result − [explorer.exe] java_lang_processbuilder.htm
Advertisements
|
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |