Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 
 package ch.cern.mig.utils;
 
 import java.util.Map;
Generic process utiitiess.

Author(s):
Massimo Paladin - massimo.paladin@gmail.com
Copyright (C) CERN 2012-2013
public class ProcessUtils {

    
Execute the given system command and return a Map containing output results and exit value.

Parameters:
command
Returns:
Map containing output results and exit value
    public static Map<StringStringexecuteIt(String command) {
        StringBuilder output = new StringBuilder();
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(command);
            Scanner sc = new Scanner(process.getInputStream());
            process.waitFor();
            while (sc.hasNext()) {
                output.append(sc.nextLine());
            }
        } catch (IOException e) {
            output.append(e.getMessage());
        } catch (InterruptedException e) {
            output.append(e.getMessage());
        }
        Map<StringStringresult = new HashMap<StringString>();
        result.put("exitValue""" + process.exitValue());
        result.put("out"output.toString());
        return result;
    }
New to GrepCode? Check out our FAQ X