Here you can find the source of execCommand(String[] cmd)
Parameter | Description |
---|---|
cmd | An array of the command & its arguments |
Parameter | Description |
---|
public static String execCommand(String[] cmd) throws java.io.IOException
//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() : ""; } }