I'm trying to execute some bash command using python. I want to display command's live output to user as well as capture it.
A sample example is like
import subporcess
# This will store output in result but print nothing to terminal
result = subprocess.run(['ls', '-lh'], check=True, universal_newlines=True, stdout=subprocess.PIPE)
print(result.stdout) # STD OUTPUT
# This will print everything to terminal result will be empty
result = subprocess.run(['ls', '-lh'], check=True, universal_newlines=True)
print(result.stdout) # OUTPUT = None
.runyou can use.check_output. Have a look at the documentationprintthis to the console yourself though..30 mintill then the user will think that the program is dead.subprocess.PIPEand make it write the output in two places at the same time.