Here you can find the source of executeIt(String command)
Parameter | Description |
---|---|
command | a parameter |
public static Map<String, String> executeIt(String command)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { /**/*w ww . j ava 2 s . c o m*/ * Execute the given system command and return a Map containing output * results and exit value. * * @param command * @return Map containing output results and exit value */ public static Map<String, String> executeIt(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<String, String> result = new HashMap<String, String>(); result.put("exitValue", "" + process.exitValue()); result.put("out", output.toString()); return result; } }