private String escapeAndJoin ( String [ ] commandline ) { // TODO: we should try to escape special characters here, depending on the OS. StringBuilder b = new StringBuilder ( ) ; Pattern specials = Pattern . compile ( "[\\ ]" ) ; for ( String arg : commandline ) { if ( b . length ( ) > 0 ) { b . append ( " " ) ; } if ( specials . matcher ( arg ) . find ( ) ) { b . append ( ' ' ) . append ( arg ) . append ( ' ' ) ; } else { b . append ( arg ) ; } } return b . toString ( ) ; }
Try to provide an escaped ready - to - use shell line to repeat a given command line .