/*
 * winExec.java
 *
 * Created on 29 de octubre de 2007, 12:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package icum.sysUtil;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;


/**
 *
 * @author miguel
 */
public class winExec {
    
    /** Creates a new instance of winExec */
    public winExec() {
    }
    public void ejecutar(){
        try {
            final Process process = Runtime.getRuntime().exec("cmd");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    public void ejecutarComando(String comando) {
        try {
            
            Runtime rt = Runtime.getRuntime();
            System.out.println("Execing " + comando);
            Process proc = rt.exec(comando);
            // any error message?
            StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR");
            
            // any output?
            StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT");
            
            // kick them off
            errorGobbler.run();
            outputGobbler.run();
            
            // any error???
            int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);
            rt.runFinalization();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    
}
