Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java run shell command

String homeDirectory = System.getProperty("user.home");
Process process;
if (isWindows) {
    process = Runtime.getRuntime()
      .exec(String.format("cmd.exe /c dir %s", homeDirectory));
} else {
    process = Runtime.getRuntime()
      .exec(String.format("sh -c ls %s", homeDirectory));
}
StreamGobbler streamGobbler = 
  new StreamGobbler(process.getInputStream(), System.out::println);
Executors.newSingleThreadExecutor().submit(streamGobbler);
int exitCode = process.waitFor();
assert exitCode == 0;
Comment

PREVIOUS NEXT
Code Example
Java :: map string list string in java 
Java :: java foreach list 
Java :: how to create immutable list java 
Java :: java save file 
Java :: java hello world 
Java :: javadoc link to class 
Java :: java get constructor 
Java :: java stream order by property 
Java :: how to change background tint color programmatically android 
Java :: create a toast message in android 
Java :: Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 
Java :: replace all punctuation in string java 
Java :: java first day of week 
Java :: select word from array 
Java :: try catch java 
Java :: thymeleaf string not equal 
Java :: how to find the largest number in a 2d array java 
Java :: java create arraylist 
Java :: get imei programmatically android 
Java :: set intersection java 
Java :: jframe visibility 
Java :: concatenate two arrays java 
Java :: java arraylist to array 
Java :: how to read input in java 
Java :: how do i print text in java 
Java :: string array to string java 
Java :: jpa default value enum 
Java :: java home mac 
Java :: from string to date 
Java :: Java how to make a number with digits 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =