import java.io.*; import java.lang.*; import java.*; import java.lang.Runtime.*; public class RunCommand { public static void main(String args[]) { MakeSystemCommand(); } public static void MakeSystemCommand() { String s = null; //String cmd = null; try { // run the Unix "ps -ef" command //cmd = "c:\\ayeddula\\dir"; File path = new File("C:/ayeddula"); String cmd = "dir"; //Runtime.getRuntime().exec(cmd, null, path); //Process p = Runtime.getRuntime().exec("C:\\winnt\\system32\\CMD.exe DIR"); //Process p = Runtime.getRuntime().exec("perl c:\\ayeddula\\alternate.pl"); Process p = Runtime.getRuntime().exec("C://ayeddula//MyDir.bat"); //Process p = Runtime.getRuntime().exec("command.com /C dir"); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("Here is the standard output of the command:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } System.exit(0); } catch (Exception e) { System.out.println("exception happened - here's what I know: " +e); e.printStackTrace(); System.exit(-1); } } }