Java exec execIt(String cmd)

Here you can find the source of execIt(String cmd)

Description

exec It

License

Open Source License

Declaration

public static String execIt(String cmd) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedInputStream;
import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static String execIt(String cmd) {
        Process process;/*from  w  ww. j av  a  2  s.c o  m*/
        String result = "";
        try {
            //cmd = "cmd /c dir";
            process = Runtime.getRuntime().exec(cmd);
            BufferedInputStream in = new BufferedInputStream(
                    process.getInputStream());
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(in));
            String lineStr;
            while ((lineStr = br.readLine()) != null) {
                result += lineStr;
            }
            br.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related

  1. execCommand(String[] cmd)
  2. execCommandLineUtility(String cmd)
  3. execGenericCommand(String[] command, String redirectOutput)
  4. execGetOutput(String[] command, String[] env)
  5. execHostName(String execCommand)
  6. execJAR(String jarPath, String vmArgs, String appArgs, String workDir)
  7. execLocalhostCmd(String cmd)
  8. exeCmdByOs(String cmd)
  9. execName()