I am trying to pipe the output of the following command to /dev/null
so that it doesn't get printed for the user that is running the program.
import os
os.system("ping -c 1 192.168.unknown.host > /dev/null")
But I get the error:
ping: unknown host 192.168.unknown.host
The problem is that this message is produced by something other than stdout
, probably stderr
and I can easily redirect it to /dev/null
using
ping -c 1 192.168.unknown.host >& /dev/null
However, when I use that in python, I get the following error:
sh: 1: Syntax error: Bad fd number
Is it possible to solve this? (I just don't want that message to be printed).