@ Nullable private String readFromProcess ( String ... args ) throws InterruptedException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ) { ProcStarter ps = launcher . launch ( ) ; Proc p = launcher . launch ( ps . cmds ( args ) . stdout ( baos ) ) ; int exitCode = p . join ( ) ; if ( exitCode == 0 ) { return baos . toString ( getComputer ( ) . getDefaultCharset ( ) . name ( ) ) . replaceAll ( "[\t\r\n]+" , " " ) . trim ( ) ; } else { return null ; } } catch ( IOException e ) { e . printStackTrace ( console . format ( "Error executing command '%s' : %s%n" , Arrays . toString ( args ) , e . getMessage ( ) ) ) ; } return null ; }
Executes a command and reads the result to a string . It uses the launcher to run the command to make sure the launcher decorator is used ie . docker . image step