Print out the output of launched brwsr launcher
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 21 Dec 2012 09:18:52 +0100
branchlauncher
changeset 36198eb1066dab1
parent 360 86f3ea771e24
child 362 a41b238056f4
Print out the output of launched brwsr
launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java
     1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Thu Dec 20 21:54:33 2012 +0100
     1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Fri Dec 21 09:18:52 2012 +0100
     1.3 @@ -27,6 +27,7 @@
     1.4  import java.net.URISyntaxException;
     1.5  import java.net.URL;
     1.6  import java.util.ArrayList;
     1.7 +import java.util.Arrays;
     1.8  import java.util.Enumeration;
     1.9  import java.util.LinkedHashSet;
    1.10  import java.util.List;
    1.11 @@ -234,15 +235,34 @@
    1.12          int port = listener.getPort();
    1.13          
    1.14          URI uri = new URI("http://localhost:" + port + page);
    1.15 +        System.err.println("Showing " + uri);
    1.16          try {
    1.17              Desktop.getDesktop().browse(uri);
    1.18          } catch (UnsupportedOperationException ex) {
    1.19              String[] cmd = { 
    1.20                  "xdg-open", uri.toString()
    1.21              };
    1.22 -            Runtime.getRuntime().exec(cmd).waitFor();
    1.23 +            System.err.println("Launching " + Arrays.toString(cmd));
    1.24 +            final Process process = Runtime.getRuntime().exec(cmd);
    1.25 +            InputStream stdout = process.getInputStream();
    1.26 +            InputStream stderr = process.getErrorStream();
    1.27 +            int res = process.waitFor();
    1.28 +            System.err.println("Exit code: " + res);
    1.29 +            drain("StdOut", stdout);
    1.30 +            drain("StdErr", stderr);
    1.31          }
    1.32 -        System.err.println("Showing " + uri);
    1.33 +    }
    1.34 +    
    1.35 +    private static void drain(String name, InputStream is) throws IOException {
    1.36 +        int av = is.available();
    1.37 +        if (av > 0) {
    1.38 +            System.err.println("v== " + name + " ==v");
    1.39 +            while (av-- > 0) {
    1.40 +                System.err.write(is.read());
    1.41 +            }
    1.42 +            System.err.println();
    1.43 +            System.err.println("^== " + name + " ==^");
    1.44 +        }
    1.45      }
    1.46  
    1.47      private class Res implements Bck2Brwsr.Resources {