Execute Shell Command From Java
Join the DZone community and get the full member experience.
Join For Free
String cmd = "ls -al";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);
}
Java (programming language)
shell
Command (computing)
Opinions expressed by DZone contributors are their own.
Comments