Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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