Java exec execCommand(String[] cmd)

Here you can find the source of execCommand(String[] cmd)

Description

Execute a shell command

License

Open Source License

Parameter

Parameter Description
cmd An array of the command & its arguments

Exception

Parameter Description

Return

The output of the command

Declaration

public static String execCommand(String[] cmd) throws java.io.IOException 

Method Source Code

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

public class Main {
    /**//from w  ww  .j  ava  2s.  c o  m
     * Execute a shell command
     * @param cmd An array of the command & its arguments
     * @return The output of the command
     * @throws java.io.IOException
     */
    public static String execCommand(String[] cmd) throws java.io.IOException {
        Process proc = Runtime.getRuntime().exec(cmd);
        java.io.InputStream is = proc.getInputStream();
        java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
        return (s.hasNext()) ? s.next().trim() : "";
    }
}

Related

  1. execCmd(String command)
  2. execCmdWindows(String cmd)
  3. execCommand(String cmd)
  4. execCommand(String command)
  5. execCommand(String command)
  6. execCommand(String[] cmd)
  7. execCommandLineUtility(String cmd)
  8. execGenericCommand(String[] command, String redirectOutput)
  9. execGetOutput(String[] command, String[] env)