I would like to run a command using subprocess.run() and then get its stdout/stderr as a string, but I want the subprocess to also print its output to the console normally while running. If I do
result = subprocess.run(['ls', '-al'])
then I can see the output printed to my console but I can't access the output after the command runs. If I do
result = subprocess.run(['ls', '-al'], capture_output=True, text=True)
I can access result.stdout and result.stderr but nothing is printed to the console while the command is running. Can I have both printing to the console and saving to result.stdout?