Created
December 26, 2018 18:17
-
-
Save a18simongv/91d26405559be6103ccac6238f025526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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