执行 cmd /c start F:\\abc.bat > out.txt
然后打开out.txt查看

解决方案 »

  1.   

    謝謝樓上的,不過這樣應該會出DOS黑框吧,我要這樣的效果是不出DOS黑框 並且在自己的java程序裏輸出
    執行時的輸出信息急,自己給自己頂下
      

  2.   

    那只有用WINDOWS API去隐藏窗口运行了,JAVA好象办不到
      

  3.   

    public class TestBat{
    public static void main(String[] args) {
            try{
                String command = "notepad.exe";
                Process child = Runtime.getRuntime().exec(command);
                child.waitFor();
            }catch(Exception e){
                System.err.println(e.getMessage());
            }
        }
    }
      

  4.   

    先把你的bat文件写好,然后在调用
    调用.exe,.bat都一样
      

  5.   

    抱歉,应该是
    child.getInputStream()
    搞错方向了
      

  6.   

    最佳答案:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;public class JavaExeBat {
        public JavaExeBat() {
        }    public static void main(String[] args) {
            Process p;
            //test.bat中的命令是ipconfig/all
            String cmd="c:\\test\\test.bat";
            
            try {
                //执行命令
                p = Runtime.getRuntime().exec(cmd);
                //取得命令结果的输出流
                InputStream fis=p.getInputStream();
                //用一个读输出流类去读
                InputStreamReader isr=new InputStreamReader(fis);
                //用缓冲器读行
                BufferedReader br=new BufferedReader(isr);
                String line=null;
                //直到读完为止
                while((line=br.readLine())!=null) {
                    System.out.println(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    如果如下:
    Windows IP Configuration   Host Name . . . . . . . . . . . . : Mickey   Primary Dns Suffix  . . . . . . . :    Node Type . . . . . . . . . . . . : Unknown   IP Routing Enabled. . . . . . . . : No   WINS Proxy Enabled. . . . . . . . : No   DNS Suffix Search List. . . . . . : domainEthernet adapter 本地连接:   Connection-specific DNS Suffix  . : domain   Description . . . . . . . . . . . : Broadcom NetXtreme Gigabit Ethernet   Physical Address. . . . . . . . . : 00-18-71-6C-0C-7D   DHCP Enabled. . . . . . . . . . . : Yes   Autoconfiguration Enabled . . . . : Yes   IP Address. . . . . . . . . . . . : 192.168.1.103   Subnet Mask . . . . . . . . . . . : 255.255.255.0   Default Gateway . . . . . . . . . : 192.168.1.1   DHCP Server . . . . . . . . . . . : 192.168.1.1   DNS Servers . . . . . . . . . . . : 202.96.134.133                                       202.96.128.68   Lease Obtained. . . . . . . . . . : 2007年7月4日 14:53:56   Lease Expires . . . . . . . . . . : 2007年7月4日 16:53:56