I'm running this:
os.system("/etc/init.d/apache2 restart")
It restarts the webserver, as it should. However, it also outputs a message like so (like it would if I had run the command directly from the terminal)
* Restarting web server apache2 ...
waiting [ OK ]
How can I disable this output?
os.system("/etc/init.d/apache2 restart >/dev/null")
will discard that output. As Noufal has said,subprocess
is preferred. If you're wanting to make a quick adjustment to pre-existing code, though, redirecting to /dev/null might be an attractive option. – Hugues