public CommandResult executeCommand(String... commandParams) throws IOException {

		if (commandParams == null || commandParams.length == 0) {
			throw new IOException("Unable to execute command. No commands provided.");
		}

		List<String> returnedLines = new ArrayList();

		Charset charset = Charset.forName(ENCODING_UTF_8);

		try {
			Process process = null;
			//One param...
			if (commandParams.length == 1) {
				process = Runtime.getRuntime().exec(commandParams[0]);
			}
			//More params...
			else {
				process = Runtime.getRuntime().exec(commandParams);
			}

			BufferedReader reader = new BufferedReader(
					new InputStreamReader(
							process.getInputStream(), charset));

			String readLine = null;
			while ((readLine = reader.readLine()) != null) {
				returnedLines.add(readLine);
			}

			BufferedReader errorReader = new BufferedReader(
					new InputStreamReader(process.getErrorStream(),charset));

			while ((readLine = errorReader.readLine()) != null) {
				returnedLines.add(readLine);
			}

			int exitValue = -1000;
			try {
				exitValue = process.waitFor();
			} catch (InterruptedException e) {
				String commandString = (commandParams == null || commandParams.length == 0) ?
						"<unknown>" : commandParams[0];

				throw new IOException("Unable to wait for command [" + commandString +
						"] to exit. " + e.getMessage(), e);
			}

			String[] rtnArr = {};
			return new CommandResult(exitValue, returnedLines.toArray(rtnArr));
		} catch (IOException ioExeption) {
			//IO Problem...
			String commandString = (commandParams == null || commandParams.length == 0) ?
					"<unknown>" : commandParams[0];

			throw new IOException("Unable to execute command/s [" + commandString + "]. " + ioExeption.getMessage(), ioExeption);
		}
	}
public CommandResult executeCommand(String... commandParams) throws IOException {

		if (commandParams == null || commandParams.length == 0) {
			throw new IOException("Unable to execute command. No commands provided.");
		}

		List<String> returnedLines = new ArrayList();

		Charset charset = Charset.forName(ENCODING_UTF_8);

		try {
			Process process = null;
			
			if (commandParams.length == 1) {
				process = Runtime.getRuntime().exec(commandParams[0]);
			}
			
			else {
				process = Runtime.getRuntime().exec(commandParams);
			}

			BufferedReader reader = new BufferedReader(
					new InputStreamReader(
							process.getInputStream(), charset));

			String readLine = null;
			while ((readLine = reader.readLine()) != null) {
				returnedLines.add(readLine);
			}

			BufferedReader errorReader = new BufferedReader(
					new InputStreamReader(process.getErrorStream(),charset));

			while ((readLine = errorReader.readLine()) != null) {
				returnedLines.add(readLine);
			}

			int exitValue = -1000;
			try {
				exitValue = process.waitFor();
			} catch (InterruptedException e) {
				String commandString = (commandParams == null || commandParams.length == 0) ?
						"<unknown>" : commandParams[0];

				throw new IOException("Unable to wait for command [" + commandString +
						"] to exit. " + e.getMessage(), e);
			}

			String[] rtnArr = {};
			return new CommandResult(exitValue, returnedLines.toArray(rtnArr));
		} catch (IOException ioExeption) {
			
			String commandString = (commandParams == null || commandParams.length == 0) ?
					"<unknown>" : commandParams[0];

			throw new IOException("Unable to execute command/s [" + commandString + "]. " + ioExeption.getMessage(), ioExeption);
		}
	}
public CommandResult executeCommand ( String ... commandParams ) throws IOException { if ( commandParams == null || commandParams . length == 0 ) { throw new IOException ( "Unable to execute command. No commands provided." ) ; } List < String > returnedLines = new ArrayList ( ) ; Charset charset = Charset . forName ( ENCODING_UTF_8 ) ; try { Process process = null ; //One param... if ( commandParams . length == 1 ) { process = Runtime . getRuntime ( ) . exec ( commandParams [ 0 ] ) ; } //More params... else { process = Runtime . getRuntime ( ) . exec ( commandParams ) ; } BufferedReader reader = new BufferedReader ( new InputStreamReader ( process . getInputStream ( ) , charset ) ) ; String readLine = null ; while ( ( readLine = reader . readLine ( ) ) != null ) { returnedLines . add ( readLine ) ; } BufferedReader errorReader = new BufferedReader ( new InputStreamReader ( process . getErrorStream ( ) , charset ) ) ; while ( ( readLine = errorReader . readLine ( ) ) != null ) { returnedLines . add ( readLine ) ; } int exitValue = - 1000 ; try { exitValue = process . waitFor ( ) ; } catch ( InterruptedException e ) { String commandString = ( commandParams == null || commandParams . length == 0 ) ? "<unknown>" : commandParams [ 0 ] ; throw new IOException ( "Unable to wait for command [" + commandString + "] to exit. " + e . getMessage ( ) , e ) ; } String [ ] rtnArr = { } ; return new CommandResult ( exitValue , returnedLines . toArray ( rtnArr ) ) ; } catch ( IOException ioExeption ) { //IO Problem... String commandString = ( commandParams == null || commandParams . length == 0 ) ? "<unknown>" : commandParams [ 0 ] ; throw new IOException ( "Unable to execute command/s [" + commandString + "]. " + ioExeption . getMessage ( ) , ioExeption ) ; } }
Executes the {@code commandParams} and returns the result.

@param commandParams The command and parameters to execute.
@return The result of the execution.

@throws IOException If execution of the command fails.

@see CommandResult
Executes the { @code commandParams } and returns the result .