Java exec executeCommand(List command)

Here you can find the source of executeCommand(List command)

Description

execute Command

License

Open Source License

Declaration

public static void executeCommand(List<String> command) throws IOException 

Method Source Code


//package com.java2s;
/*/*from w ww  .jav  a2 s . c o m*/
*
* BitTwiddler - BMP transcoder
* Copyright (C) 2015  Tyler Pitchford
*
* This file is part of BitTwiddler.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING.  If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

public class Main {
    public static void executeCommand(List<String> command) throws IOException {
        ProcessBuilder pb = new ProcessBuilder();
        pb.command(command);

        System.out.println("Executing: " + pb.command());

        Process process = pb.start();

        BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));

        BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));

        // read the output from the command
        String s = null;
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }

        // read any errors from the attempted command
        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }
    }
}

Related

  1. executeCmdForReader(String cmd)
  2. executeComand(String[] comand)
  3. executeCommand(final ProcessBuilder pb)
  4. executeCommand(final String cmd)
  5. executeCommand(List cmdArray)
  6. executeCommand(String cmd)
  7. executeCommand(String cmd)
  8. executeCommand(String comand)
  9. executeCommand(String command)