Java exec executeShellCmdAndReturn(String cmd)

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

Description

Execute a shell command and throw exception if command failed.

License

Open Source License

Parameter

Parameter Description
cmd shell command to be executed.

Exception

Parameter Description

Declaration


public static void executeShellCmdAndReturn(String cmd) throws IOException 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.io.*;

public class Main {
    /**//from  w w  w.j  a v  a2s.co  m
     * Execute a shell command and throw exception if command failed.
     *
     * @param cmd shell command to be executed.
     * @throws java.io.IOException in case of execution failed
     */
    //===============================================================
    public static void executeShellCmdAndReturn(String cmd) throws IOException {
        System.out.println(cmd);
        Process process = Runtime.getRuntime().exec(cmd);

        // get command output stream and
        // put a buffered reader input stream on it.
        InputStream inputStream = process.getInputStream();
        new BufferedReader(new InputStreamReader(inputStream));

        // do not read output lines from command
        // Do not check its exit value
    }
}

Related

  1. executeProcess(final String[] cmds)
  2. executeProcess(String command)
  3. executeProcessAndGetOutputAsStringList(final String command)
  4. executePUT(DataInputStream sockInp, DataOutputStream sockOutp)
  5. executeServer()
  6. executeShellCommand(String command)
  7. executeShellCommand(String command)
  8. executeShellCommand(String command, File dir)
  9. executeShellCommand(String commandName)