日期:2014-05-20  浏览次数:20718 次

java调用bat文件的问题
package   test;

import   java.io.IOException;

public   class   Test   {

        public   static   void   main(String[]   args)   {
               
                System.out.println();
                String   s   =   "cmd   /C   "   +   System.getProperty( "user.dir ")   +   System.getProperty( "file.separator ")
                +   "batTest.bat ";
                try   {
                Runtime.getRuntime().exec(s);
                }   catch   (IOException   e)   {
                        e.printStackTrace();
                }
        }

}
执行上述main方法,程序正常结束,但是批处理文件没有执行,双击这个批处理文件是可以执行的。
不知道是什么原因。

------解决方案--------------------
冒似少执行了一个方法。
------解决方案--------------------
up,确实不执行。
------解决方案--------------------
这样就可以执行了
package test;

import java.io.IOException;

public class Test {

public static void main(String[] args) {
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec( "cmd.exe /c "+ "start /min d:\\a.bat ");
} catch (IOException e) {
e.printStackTrace();
}
}

}