6

I have a python program that opens several urls in seperate tabs in a new browser window, however when I run the program from the command line and open the browser using

webbrowser.open_new(url)

The stderr from firefox prints to bash. Looking at the docs I can't seem to find a way to redirect or suppress them

I have resorted to using

browserInstance = subprocess.Popen(['firefox'], stdout=log, stderr=log)

Where log is a tempfile & then opening the other tabs with webbrowser.open_new.

Is there a way to do this within the webbrowser module?

David Miller
  • 2,189
  • 2
  • 15
  • 17

3 Answers3

6

What is webbrowser.get() giving you?

If you do

 webbrowser.get('firefox').open(url)

then you shouldn't see any output. The webbrowser module choses to leave stderr for some browsers - in particular the text browsers, and then ones where it isn't certain. For all UnixBrowsers that have set background to True, no output should be visible.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
0

What about sending the output to /dev/null instead of a temporary file?

Andrew Keeton
  • 22,195
  • 6
  • 45
  • 72
0

I think Martin is right about Unix systems, but it looks like things are different on Windows. Is this on a Windows system?

On Windows it looks like webbrowser.py is either going to give you a webbrowser.WindowsDefault browser, which opens the url using

os.startfile(url)

or if Firefox is present it's going to give you a webbrowser.BackgroundBrowser, which starts the browser on Windows using:

p = subprocess.Popen(cmdline)

It looks like only Unix browsers have the ability to redirect stderr in the webbrowser module. You should be able to find out what browser type you're getting by doing

>>> webbrowser.get('firefox')

In a Python interactive console.

ryan_s
  • 7,826
  • 3
  • 27
  • 28