'Remove an extra output from subprocess module in python

I am trying to execute commands using the subprocess module on windows, but there is an output which is "CompletedProcess(args=['command'], returncode=0)" How can I remove this output and show only my command output?

My code:

import subprocess

command = subprocess.run(['whoami'])

print(command)


Solution 1:[1]

You can utilise capture_output & text to print out your output.

command = subprocess.run(['whoami'], capture_output=True, text=True)
print(command.stdout)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shlim