public static String productInfo ( File installDirectory , String action ) throws PluginExecutionException { Process pr = null ; InputStream is = null ; Scanner s = null ; Worker worker = null ; try { String command ; if ( OSUtil . isWindows ( ) ) { command = installDirectory + "\\bin\\productInfo.bat " + action ; } else { command = installDirectory + "/bin/productInfo " + action ; } pr = Runtime . getRuntime ( ) . exec ( command ) ; worker = new Worker ( pr ) ; worker . start ( ) ; worker . join ( 300000 ) ; if ( worker . exit == null ) { throw new PluginExecutionException ( "productInfo command timed out" ) ; } int exitValue = pr . exitValue ( ) ; if ( exitValue != 0 ) { throw new PluginExecutionException ( "productInfo exited with return code " + exitValue ) ; } is = pr . getInputStream ( ) ; s = new Scanner ( is ) ; // use regex to match the beginning of the input s . useDelimiter ( "\\A" ) ; if ( s . hasNext ( ) ) { return s . next ( ) ; } return null ; } catch ( IOException ex ) { throw new PluginExecutionException ( "productInfo error: " + ex ) ; } catch ( InterruptedException ex ) { worker . interrupt ( ) ; Thread . currentThread ( ) . interrupt ( ) ; throw new PluginExecutionException ( "productInfo error: " + ex ) ; } finally { if ( s != null ) { s . close ( ) ; } if ( is != null ) { try { is . close ( ) ; } catch ( IOException e ) { } } if ( pr != null ) { pr . destroy ( ) ; } } }
Runs the productInfo command and returns the output