// reads shell commands one per line from stdin // executes them with Runtime.exec // prints results // can't use it to recurse, etc: won't run sh properly // because input isn't handed along import java.io.*; public class exec { public static void main(String[] args) { exec r = new exec(); } exec() { try { Runtime rt = Runtime.getRuntime(); DataInputStream din = new DataInputStream(System.in); String s; while ((s = din.readLine()) != null) { Process p = rt.exec(s); // do we need to wait for completion here? p.waitFor(); int stat = p.exitValue(); DataInputStream pin = new DataInputStream(p.getInputStream()); while ((s = pin.readLine()) != null) { System.out.println(s); } pin.close(); } } catch (Exception e) { // IO, InterruptedException e.printStackTrace(); } } }