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() 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. DeclarationFollowing is the declaration for java.lang.ProcessBuilder.command() method public List<String> command() ParametersNA Return ValueThis method returns this process builder's program and its arguments ExceptionNA Getting process details 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 to it. Using that list, we've initialized a ProcessBuilder instance. Now using command() method, we've printed the underlying operating system command name and other details. 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<String> 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());
}
}
OutputLet us compile and run the above program, this will produce the following result − [notepad.exe] Getting process details 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. Now using command() method, we've printed the underlying operating system command name and other details. 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<String> list = new ArrayList<>();
list.add("calc.exe");
// create the process builder
ProcessBuilder pb = new ProcessBuilder(list);
// get the command list
System.out.println(pb.command());
}
}
OutputLet us compile and run the above program, this will produce the following result − [calc.exe] Getting process details for Windows 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. Now using command() method, we've printed the underlying operating system command name and other details. 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<String> list = new ArrayList<>();
list.add("explorer.exe");
// create the process builder
ProcessBuilder pb = new ProcessBuilder(list);
// get the command list
System.out.println(pb.command());
}
}
OutputLet us compile and run the above program, this will produce the following result − [notepad.exe] java_lang_processbuilder.htm
Advertisements
|
| You are visitor 01402503 — 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. |