public final ReturnValue execute ( final ICommandLine cl ) { File fProcessFile = new File ( cl . getOptionValue ( "executable" ) ) ; StreamManager streamMgr = new StreamManager ( ) ; if ( ! fProcessFile . exists ( ) ) { return new ReturnValue ( Status . UNKNOWN , "Could not exec executable : " + fProcessFile . getAbsolutePath ( ) ) ; } try { String [ ] vsParams = StringUtils . split ( cl . getOptionValue ( "args" , "" ) , false ) ; String [ ] vCommand = new String [ vsParams . length + 1 ] ; vCommand [ 0 ] = cl . getOptionValue ( "executable" ) ; System . arraycopy ( vsParams , 0 , vCommand , 1 , vsParams . length ) ; Process p = Runtime . getRuntime ( ) . exec ( vCommand ) ; BufferedReader br = ( BufferedReader ) streamMgr . handle ( new BufferedReader ( new InputStreamReader ( p . getInputStream ( ) ) ) ) ; StringBuilder msg = new StringBuilder ( ) ; for ( String line = br . readLine ( ) ; line != null ; line = br . readLine ( ) ) { if ( msg . length ( ) != 0 ) { msg . append ( System . lineSeparator ( ) ) ; } msg . append ( line ) ; } int iReturnCode = p . waitFor ( ) ; return new ReturnValue ( Status . fromIntValue ( iReturnCode ) , msg . toString ( ) ) ; } catch ( Exception e ) { String message = e . getMessage ( ) ; LOG . warn ( getContext ( ) , "Error executing the native plugin : " + message , e ) ; return new ReturnValue ( Status . UNKNOWN , "Could not exec executable : " + fProcessFile . getName ( ) + " - ERROR : " + message ) ; } finally { streamMgr . closeAll ( ) ; } }
The first parameter must be the full path to the executable .