42529

suppress/redirect stderr when calling python webrowser

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?

Answer3:

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.

Recommend

  • Vue.js update only works if other property changed?
  • Data not aligned correctly in Visual Studio if run in debugger
  • Login using Jsoup
  • Sort os.listdir files Python
  • Facebook Login Button: Can I prevent auto page reload after login?
  • Make a List from a Tuple List on F#
  • Unable to DROP a MySQL Table
  • SQL LIKE Column Value Plus Wildcard DB2
  • Using `awk` to print number of lines in file in the BEGIN section
  • Running Jupyter Notebook from cmd raises ModuleNotFoundError: No module named pysqlite2
  • On Gitlab, how to compare a file of two different commits
  • Convert a FileObject into a File
  • How do you use Keras LeakyReLU in Python?
  • is Security free in Elastic search Stack Features?
  • How does one upload a photo to twitter with the API function POST statuses/update_with_media
  • Python script won't exec from php when specific library is used
  • Refreshing a page with JavaScript href for Google Translate in Firefox
  • boto3 S3 Object Parsing
  • scipy.signal's convolve differs from calculated result
  • select multiple elements with group by in spark.sql
  • Identify xml text elements with Schematron
  • How to add tag during runtime in C#
  • Move UIView per UIBezierPath [closed]
  • Retrieving Application's DisplayName/UninstallString from Registry Using Powershell
  • CABasicAnimation creates empty default value copy of CALayer
  • Spongycastle is missing many algorithms when loaded on android
  • trigger ontouch event programmatically
  • How to merge objects within array based on attribute
  • What is the best way to cache and reuse immutable singleton objects in Java?
  • Make checkout phone field optional for specific countries in WooCommerce
  • calling IO Operations from thread in ruby c extension will cause ruby to hang
  • Angular 4: Responsive Grid List
  • Write to .csv file with PHP (Commas in Data Error)