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 {
    public static String exec(String cmd) {
        StringBuilder sb = new StringBuilder();
        try {
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec(cmd);
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line);
                sb.append("\n");
            }
            br.close();
            if (process.waitFor() != 0) {
                System.err.println("exit value = " + process.exitValue());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
}