use
Runtime.getRuntime().exec("cmd.exe /c D:\\MakeClassAndJar.bat");

解决方案 »

  1.   

    to bsd(小红帽菜鸟)import java.lang.Runtime;public class Test {
    public static void main(String[] args)
    {
    try {
    (Runtime.getRuntime()).exec("cmd.exe /c dir/s");
    System.out.print("11111111111111111111111111111");
    }
    catch(java.io.IOException e) {
    System.out.print("5555555555555555555555555555");
    }
    }
    }以上是我的测试程序,虽然顺利通过但是,没有得到结果?为什么?
      

  2.   

    To get the output of Runtime.getRuntime().exec("cmd.exe /c dir/s");
    you must do so:
    --------------
    import java.io.*;public class testRuntime {
      public static void main(String[] args){
        try {
          Process p = Runtime.getRuntime().exec("cmd.exe /c dir/s");
          BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
          String line;
          while ((line = input.readLine()) != null) {
            System.out.println(line);
          }
          input.close();
          System.out.print("11111111111111111111111111111");
        }catch(java.io.IOException e) {
          System.out.print("5555555555555555555555555555");
        }
      }
    }
      

  3.   

    http://coldjava.hypermart.net/servlets/shell.htm
      

  4.   

    谢谢你, bsd(小红帽菜鸟)  结账了