Question: When using subprocess or os libraries, executing the command returns the result in terminal. I want to be able to assign the output to a variable without getting any output returned to the terminal.

```
pid = subprocess.call(['pidof', process])

pid = os.system('pidof ' + process)

```

I only want to assign the variable pid, not return text to terminal. I was using the 'commands' library earlier, however it is not supported by python3.

Answer: 
You can try check\_output.

```
import subprocess
output = subprocess.check_output("COMMAND_TO_EXECUTE", shell=True)

```
Have you tried redirect the command output to DEVNULL?

```
FNULL = open(os.devnull, 'w')
retcode = subprocess.call(['pidof', process], stdout=FNULL, stderr=subprocess.STDOUT)

```