/** * Execute.java * * Created: Tue Oct 24 18:10:18 2000 * * @author David Green * @version 1.01 10 August 2004 -- note about cmd /c and locked down computers */ import java.io.*; public class Execute { public static void main(String[] args) throws IOException { String s; // cmd /c (or command /c) is needed for internal commands // but not for external commands like ping // String command = "cmd /c dir"; // Summer 2004 EE333 students report that the Engineering Lab // computers are locked down in such a way as to prevent // proper execution of ANY command without running it within // the cmd /c shell . String command = "ping 138.26.1.1"; System.out.println("Execute - "); Runtime rt = Runtime.getRuntime(); Process p = rt.exec( command ); BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); while ( ( s = br.readLine() ) != null ) System.out.println( s ); } } // Execute