I need to use os.system() a few times in my script, but I don’t want errors from the shell to appear in my script’s window. Is there a way to do this? I guess it’s sort of like silent commands, running to their full extent, but not returning any text. I can’t use ‘try’, because it’s not a Python error.
Share
You could redirect the command’s standard error away from the terminal. For example:
P.S. As pointed out by @Spencer Rathbun, the
subprocessmodule should be preferred overos.system(). Among other things, it gives you direct control over the subprocess’s stdout and stderr.