Skip to content

Instantly share code, notes, and snippets.

@a18simongv
Created December 26, 2018 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a18simongv/91d26405559be6103ccac6238f025526 to your computer and use it in GitHub Desktop.
Save a18simongv/91d26405559be6103ccac6238f025526 to your computer and use it in GitHub Desktop.
package runtimeCase;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class RuntimeExample {
public static void main(String[] args) {
//take the runtime of java application
Runtime builder = Runtime.getRuntime();
//execute commands line
String cmd = "ls -l";
try {
//execute the command and save the process in out
Process out = builder.exec(cmd);
//take the result and print it on screen
BufferedReader bf = new BufferedReader(new InputStreamReader(out.getInputStream()));
String linea;
while( (linea=bf.readLine()) != null) {
System.out.println(linea);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment