public static StringBuffer runCommand ( String [ ] cmd ) { StringBuffer retval = new StringBuffer ( MAX_OUTPUT_LENGTH ) ; Process p ; try { p = Runtime . getRuntime ( ) . exec ( cmd ) ; InputStream tmp = p . getInputStream ( ) ; p . waitFor ( ) ; int c ; while ( ( c = tmp . read ( ) ) != - 1 ) retval . append ( ( char ) c ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } return retval ; }
Runs a shell command in the system and provides a StringBuffer with the output of the command .