public static int execFromPath ( final String command , final String [ ] parms , final OutputStream out , final DirectoryResource path ) throws IOException { Assert . notNull ( command , "Command must not be null." ) ; Assert . notNull ( path , "Directory path must not be null." ) ; Assert . notNull ( out , "OutputStream must not be null." ) ; try { String [ ] commandTokens = parms == null ? new String [ 1 ] : new String [ parms . length + 1 ] ; commandTokens [ 0 ] = command ; if ( commandTokens . length > 1 ) { System . arraycopy ( parms , 0 , commandTokens , 1 , parms . length ) ; } ProcessBuilder builder = new ProcessBuilder ( commandTokens ) ; builder . directory ( path . getUnderlyingResourceObject ( ) ) ; builder . redirectErrorStream ( true ) ; Process p = builder . start ( ) ; InputStream stdout = p . getInputStream ( ) ; Thread outThread = new Thread ( new Receiver ( stdout , out ) ) ; outThread . start ( ) ; outThread . join ( ) ; return p . waitFor ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; return - 1 ; } }
Execute a native system command as if it were run from the given path .