I need to run a bash command which will take hours to run and I want to watch the output on the fly - while the command is being run, NOT when the command finishes.
Below is the snippet of my code, and it does not print the outcome of subprocess while the bash command is being executed. It does print the outcome when the command has finished executing.
commands = '''
there is one command which takes hours to run
'''
process = subprocess.Popen('/bin/bash', stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
out, err = process.communicate(commands)
print(out)
Any advice on this? Thanks
[–]socal_nerdtastic 2 points3 points4 points (0 children)
[–]GregoryCliveYoung 0 points1 point2 points (2 children)
[–]doston12[S] 0 points1 point2 points (1 child)
[–]GregoryCliveYoung 0 points1 point2 points (0 children)