I am using a subproccess like this to get output from shell.
with subprocess.Popen(['bash', '-c', '. /root/myFile.sh;',
' func ' ], stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
bufsize=1,universal_newlines=True) as proc_launch:
for line in proc_launch.stdout:
print(line, end='')
It's giving line by line output, while I want to get output in a way like last 3 or 4 lines plus current line. Is there any method to do that in a clean way?