
Question:
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?
Answer1: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.
Answer2:What about sending the output to /dev/null
instead of a temporary file?
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.