Java exec execLocalhostCmd(String cmd)

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

Description

exec Localhost Cmd

License

Apache License

Declaration

public static String execLocalhostCmd(String cmd) throws IOException 

Method Source Code


//package com.java2s;
//  Licensed under the Apache License, Version 2.0 (the "License");

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static String execLocalhostCmd(String cmd) throws IOException {

        Runtime runtime = Runtime.getRuntime();
        Process proc = runtime.exec(cmd);

        InputStream is = proc.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader bufReader = new BufferedReader(isr);

        String line = "";
        StringBuffer sbuf = new StringBuffer("");
        while ((line = bufReader.readLine()) != null) {
            sbuf.append(line);/* w  w w  . j av  a2 s.co  m*/
        }

        try {
            if (proc.waitFor() != 0) {
                //System.err.println("Exit Value = " +   proc.exitValue());
            }
        } catch (InterruptedException e) {
            System.err.println(e);
        }
        return sbuf.toString();
    }
}

Related

  1. execGenericCommand(String[] command, String redirectOutput)
  2. execGetOutput(String[] command, String[] env)
  3. execHostName(String execCommand)
  4. execIt(String cmd)
  5. execJAR(String jarPath, String vmArgs, String appArgs, String workDir)
  6. exeCmdByOs(String cmd)
  7. execName()
  8. execPrint(final boolean out, final String... command)
  9. execProcess(String process)