Avoid os.system()
by all means, and use subprocess instead:
with open(os.devnull, 'wb') as devnull:
subprocess.check_call(['/etc/init.d/apache2', 'restart'], stdout=devnull, stderr=subprocess.STDOUT)
This is the subprocess
equivalent of the /etc/init.d/apache2 restart &> /dev/null
.
There is subprocess.DEVNULL
on Python 3.3+:
#!/usr/bin/env python3
from subprocess import DEVNULL, STDOUT, check_call
check_call(['/etc/init.d/apache2', 'restart'], stdout=DEVNULL, stderr=STDOUT)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…