Runtime.getRuntime().exec(String cmd)

解决方案 »

  1.   

    runtime类来直接执行就可以!Runtime.exec(".bat");
      

  2.   

    好象不行呀!我试了很多次之后总结出来一个经验,就是如果调用的是windows命令(例如notepad.exe、iexplore.exe)就没有问题,但是如果调用的是基于dos的命令(例如ping.exe、sqlldr.exe)就会出现一个黑乎乎的dos窗口,然后就一点的结果都没有,.bat也是如此。还请楼上的两位大侠指教。
      

  3.   

    有些 bat 文件要求系统中有一些环境变量,比如要运行tomcat中的startup.bat就要求系统中要求将系统变量设计  CATALINA_HOME  为 c:\tomcat
    然后即可以运行了,而且在JBuider中运行不行,打包成 exe文件就右以运行了。
    要知道这个bat文件可不可以直接运行,只要进入Dos 窗口,然后再运行程序的完全路径如:
    在C盘根据目录下运行 c:\tomcatc\bin\startup.bat 如果系统变量中没有CATALINA_HOME,应付提示出错。
    但如果你进入c:\tomcat\bin\ 目录下再运行 startup.bat 就可以。因为它会在当前目录下找到需要的文件。希望上面的信息能能你以帮助。
      

  4.   

    能够避免调用,最好不用。Runtime.exec 对 win16/dos等支持的不好.常常会造成 block 和 event deadlock.
    The Runtime.exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Win32, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.