Java exec exec(String command)

Here you can find the source of exec(String command)

Description

exec

License

Open Source License

Declaration

public static String exec(String command) 

Method Source Code


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

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static String exec(String command) {
        try {/*from  ww  w  .  ja v a  2  s.  com*/
            Process process = Runtime.getRuntime().exec(command);
            InputStream errorStream = process.getErrorStream();
            byte[] buffer = new byte[1024];
            int readBytes;
            StringBuilder stringBuilder = new StringBuilder();
            while ((readBytes = errorStream.read(buffer)) > 0) {
                stringBuilder.append(new String(buffer, 0, readBytes));
            }
            return stringBuilder.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. exec(String cmd, File dir)
  2. exec(String command)
  3. exec(String command)
  4. exec(String command)
  5. exec(String command)
  6. exec(String command)
  7. exec(String command, String workingDir)
  8. exec(String command, String[] args_, String[] environment)
  9. exec(String command[], boolean stop)