Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    /**
     * Run a command and return its output.
     */
    public static String systemOut(String command) throws Exception {
        int c;
        String[] cmd = new String[3];
        cmd[0] = System.getProperty("SHELL", "/bin/sh");
        cmd[1] = "-c";
        cmd[2] = command;
        Process p = Runtime.getRuntime().exec(cmd);

        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        StringBuilder s = new StringBuilder();
        while ((c = r.read()) != -1) {
            s.append((char) c);
        }
        p.waitFor();

        return s.toString();
    }
}