Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.DataInputStream;

public class Main {

    public static String execCmd(String cmd) {

        String result = "";
        DataInputStream dis = null;

        try {
            Process p = Runtime.getRuntime().exec(cmd);
            dis = new DataInputStream(p.getInputStream());
            String line = null;
            while ((line = dis.readLine()) != null) {
                line += "\n";
                result += line;
            }
            p.waitFor();
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return result;
    }
}