0

I'm running this code on a Raspberry Pi 3b+ (debian buster)

import subprocess

CAN_SET_DEV_BITRATE = ['sudo','ip','link','set','can0','type','can','bitrate','100000']
CAN_SET_DEV_UP = ['sudo','ip','link','set','up','can0']

try:
    subprocess.check_output(CAN_SET_DEV_BITRATE)
    subprocess.check_output(CAN_SET_DEV_UP)
except:
    pass

When this code runs, it outputs RTNETLINK answers: Device or resource busy. How do I stop it from printing this to console?

Peter Kapteyn
  • 354
  • 1
  • 13
  • 1
    `stderr=subprocess.DEVNULL` on a new enough Python to have it, or `stderr=open('/dev/null', 'w')` on one that isn't. – Charles Duffy Jul 17 '20 at 16:52
  • BTW, the "in Python 2.7" duplicate is the one with the better answers, even if you're on Python 3 (there's a topical answer there too). – Charles Duffy Jul 17 '20 at 16:54

0 Answers0