private String executeCommand ( ) throws IOException , InterruptedException { ProcessBuilder processBuilder = new ProcessBuilder ( command ) ; ByteArrayOutputStream commandOutput = new ByteArrayOutputStream ( ) ; Process process = processBuilder . start ( ) ; try { IOUtils . copy ( process . getInputStream ( ) , commandOutput , processOutputLimit ) ; process . waitFor ( ) ; if ( process . exitValue ( ) != 0 ) { throw new IllegalStateException ( "Command returned non-zero exit value: " + process . exitValue ( ) ) ; } return new String ( commandOutput . toByteArray ( ) , StringUtils . UTF8 ) ; } finally { process . destroy ( ) ; } }
Execute the external process to retrieve credentials .