2

I am working on writing a console application that, depending on the menu item selected, pop open the user's web browser to a predefined URL. To achieve this, I am using the Desktop class in the following way (abridged):

    Desktop desktop = Desktop.getDesktop();

    ...

    String path = "https://www.google.com/";
    desktop.browse(URI.create(path));

The problem that I am having, is that the browse method seems to print text to stdout / stderr, even though the URL has been opened properly; this messes with my console prompts.

How can I tell Desktop.browse() to not print anything to sdtout / stderr?

edit

This seems to be due to the fact that the managed OS that I am running has a wrapper around firefox, whose shebang is defined as #!/bin/bash -x causing the script to execute verbosely.

Matt Clark
  • 27,671
  • 19
  • 68
  • 123
  • just tried on OSX with Chrome as default browser, there nothing is printed. It probably is the script. But Desktop.browse() is delegated to DesktopPeer.browse() which is a native implementation so yo I don't think that you will have a chance to get the stdout/stderr from the OS process. – P.J.Meisch Mar 23 '17 at 18:03
  • Just a thought, but would calling `System.setOut/setErr()` just before calling `desktop.browse()` work? – Klitos Kyriacou Mar 23 '17 at 18:13
  • @KlitosKyriacou using [this answer](http://stackoverflow.com/a/4799195), trying to set both Out and Err to a null stream, has no effect - the output I am seeing in my console appears to never come through any of the Java PrintStreams, as @ PJ has said - this may just be the nature of the call in that it will execute a native impl. – Matt Clark Mar 23 '17 at 18:22

0 Answers0