view src/main/java/org/icedrobot/ika/runtime/IkaRuntime.java @ 12:5fa4fe467471

Refactor framework and plugins.
author Mario Torre <neugens.limasoftware@gmail.com>
date Tue, 29 Mar 2011 23:53:18 +0200
parents
children 8a417ad3e271
line wrap: on
line source

/*
 * IKA - IcedRobot Kiosk Application
 * Copyright (C) 2011  IcedRobot team
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.icedrobot.ika.runtime;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.icedrobot.ika.plugins.IkaPluginException;

public class IkaRuntime {

    /**
     * Executes the given command on the passed path.
     */
    public static void exec(String command, File path) {
        try {
            System.err.println("command: " + command + ", path: " + path);
            Process process = Runtime.getRuntime().exec(command, null, path);

            InputStream is = process.getInputStream();
            InputStreamReader reader = new InputStreamReader(is);

            BufferedReader br = new BufferedReader(reader);

            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }

        } catch (IOException ex) {
            Logger.getLogger(IkaRuntime.class.getName()).
                    log(Level.SEVERE, "cannot execute: " + command, ex);
            throw new IkaPluginException("cannot execute: " + command, ex);
        }
    }
}