Question: ```
try:
    folderSizeInMB= int(subprocess.check_output('du -csh --block-size=1M', shell=True).decode().split()[0])
    print('\t\tTotal download progress (MB):\t' + str(folderSizeInMB), end = '\r')
except Exception as e:
    print('\t\tDownloading' + '.'*(loopCount - gv.parallelDownloads + 3), end = '\r')

```

I have this code in my script because for some reason my unix decided to not find 'du' command. It throws an error `/bin/sh: du: command not found`.

My hope with this code was that even though my program runs into this error, it will just display the message in the `except` block and move-along. However, it prints the error before displaying the message in the `except` block. Why is it doing so? Is there a way for me to suppress the error message displayed by the `try` block?

Thanks.

EDIT:
I rewrote the code after receiving the answer like shown below and it works. I had to rewrite only one line:

```
folderSizeInMB= int(subprocess.check_output('du -csh --block-size=1M', shell=True, stederr=subprocess.DEVNULL).decode().split()[0])

```

Answer: 
The error is being shown by the shell, printing to stderr. Because you’re not redirecting its stderr, it just goes straight through to your own program’s stderr, which goes to your terminal.

If you don’t want this—or any other shell features—then the simplest solution is to just not use the shell. Pass a list of arguments instead of a command line, and get rid of that `shell=True`, and the error will become a normal Python exception that you can handle with the code you already have.

If you just use the shell for some reason, you will need to redirect its stderr. You can pass `stderr=subprocess.STDOUT` to make it merge in with the stdout that you’re already capturing, or `subprocess.DEVNULL` to ignore it. The `subprocess` module docs explain all of the options nicely, so read them, decide which behavior you want, and do that.
You can try redirecting the stderr to null to prevent the error from displaying. 

```
import sys

class DevNull:
    def write(self, msg):
        pass

sys.stderr = DevNull()

```