private static String [ ] getOpenBrowserCommand ( String url ) throws IOException , InterruptedException { if ( IS_WINDOWS ) { return new String [ ] { "rundll32" , "url.dll,FileProtocolHandler" , url } ; } else if ( IS_MAC ) { return new String [ ] { "/usr/bin/open" , url } ; } else if ( IS_LINUX ) { String [ ] browsers = { "google-chrome" , "firefox" , "opera" , "konqueror" , "epiphany" , "mozilla" , "netscape" } ; for ( String browser : browsers ) { if ( Runtime . getRuntime ( ) . exec ( new String [ ] { "which" , browser } ) . waitFor ( ) == 0 ) { return new String [ ] { browser , url } ; } } throw new UnsupportedOperationException ( "Cannot find a browser" ) ; } else { throw new UnsupportedOperationException ( "Opening browser is not implemented for your OS (" + OS_NAME + ")" ) ; } }
Returns the command to execute to open the specified URL according to the current OS .