All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.util.ShellUtils Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package com.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class ShellUtils {

    public static String ex(ShellBean shell) {
        String result = "";
        ArrayList list = shell.getList();
        for (String string : list) {
            result = ShellUtils.e(string);
        }
        return result;
    }

    public static String e(String commandStr) {
        BufferedReader br = null;
        StringBuilder sb = null;
        try {
            Process p = Runtime.getRuntime().exec(commandStr);
            br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            sb = new StringBuilder();
            while ((line = br.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (Exception e) {
            return e.toString();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                    return e.toString();
                }
            }
        }
        return sb.toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy