java代码调用bat文件

package com.gyb;
import java.io.IOException;
import java.io.InputStream;

public class InvokeBat4 {
    public void runbat(String batName) {
        String cmd = "cmd /k start D:\\new\\news.bat";// pass
        try {
            Process ps = Runtime.getRuntime().exec(cmd);
            InputStream in = ps.getInputStream();
            int c;
            while ((c = in.read()) != -1) {
                System.out.print(c);// 如果你不需要看输出,这行可以注销掉
            }
            in.close();
            ps.waitFor();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("child thread donn");
    }

    public static void main(String[] args) {
        InvokeBat4 test1 = new InvokeBat4();
        test1.runbat("news");
        System.out.println("main thread");
    }
}

------bat文件中这样写

d:& cd new
java -jar -Xmn600m -Xms1200m -Xmx1200m lmsp-news-snatch.jar
exit

posted @ 2017-03-22 19:56  你猜我是谁109  阅读(15673)  评论(2编辑  收藏  举报