Archive for April, 2006

You are currently browsing the archives of Enabling Technology .

Updated Java Commader

/*
* CommanderExecuter.java
*
* Created on 2006年4月25日, 下午10:44
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.test.tools.prototypes;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
*
* @author yyang
*/
public class CommanderExecuter {
    public static void main(String[] args) {
        Map  env = new HashMap();
        env.put("EA_COM_VIEW_ROOT","D:/p4/yyang-APSHADESK008-asia-appletdev2.2.1");
        call(new String []{"cmd","/c","bld.bat jvmtest"},env,"D:/p4/yyang-APSHADESK008-asia-appletdev2.2.1/java/build");
    }
    public static void call(String [] cmd, Map envMap,String dir){
        ProcessBuilder pb = new ProcessBuilder(cmd);
        Map<String, String> env = pb.environment();
        env.putAll(envMap);
        pb.directory(new File(dir));
        try {
            Process process = pb.start();
            // any error message?
            StreamGobber errorGobbler = new
                    StreamGobber(process.getErrorStream(), "ERROR");
            // any output?
            StreamGobber outputGobbler = new
                    StreamGobber(process.getInputStream(), "OUTPUT");
            // kick them off
            errorGobbler.start();
            outputGobbler.start();
            // 检查命令是否失败。
            try {
                if (process.waitFor() != 0) {
                    System.err.println("exit value = " +
                            process.exitValue());
                }
            } catch (InterruptedException e) {
                System.err.print(e);
                e.printStackTrace();
            }
        }catch(Exception ex){
            ex.printStackTrace();;
        }
    }
}

Posted by micas on Apr 25th 2006 | Filed in JavaBasic, Enabling-tech | Comments (0)