Package ca.pgon.st.light6

Source Code of ca.pgon.st.light6.Console

/*
    Small Tools - Some basic libraries for developing and testing http://www.pgon.ca/st
    Copyright (C) 2013-2014 Small Tools (info@pgon.ca)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
package ca.pgon.st.light6;

import ca.pgon.st.light6.exception.StLightException;

/**
* Some tools to execute commands in the console.
*
* @author Simon Levesque
*
*/
public final class Console {
    /**
     * Execute the command, display the outputs to the screen while waiting for it to complete.
     *
     * @param command
     */
    public static void executeAndWait(String command) {
        Runtime runtime = Runtime.getRuntime();
        try {
            Process process = runtime.exec(command);

            process.getOutputStream().close();
            StreamsUtils.flowStreamNonBlocking(process.getInputStream(), System.out);
            StreamsUtils.flowStreamNonBlocking(process.getErrorStream(), System.err);
            process.waitFor();
        } catch (Exception e) {
            throw new StLightException(e);
        }
    }

    private Console() {
    }

}
TOP

Related Classes of ca.pgon.st.light6.Console

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.