private static String runCommand ( final String [ ] cmd ) throws IOException , InterruptedException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; Process process = Runtime . getRuntime ( ) . exec ( cmd ) ; int c ; InputStream in = process . getInputStream ( ) ; while ( ( c = in . read ( ) ) != - 1 ) { baos . write ( c ) ; } in = process . getErrorStream ( ) ; while ( ( c = in . read ( ) ) != - 1 ) { baos . write ( c ) ; } process . waitFor ( ) ; return new String ( baos . toByteArray ( ) ) ; }
Run the command synchronously and return clubbed standard error and output stream s data .