Hi.
How can I get subprocess.Popen.stdout size?
Before reading from Popen.stdout I want to check its size, then get bytes from it.
def execute_bash(self):
wait_sec = 5
import time
import subprocess
wForceKill = True
res = subprocess.Popen(self.command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for i in range(wait_sec):
res.poll()
if res.returncode != None:
wForceKill = False
break
time.sleep(1.0)
if wForceKill: # inform about abort!
res.terminate()
strm = res.stdout.detach()
# here I need determine stdout's size!!!
if stdout_size > 0:
res_out = strm.read(n)
if res_out == None:
res_out = ""
self.result = b"Subprocess was killed! Additional info:" + res_out
else: # read output in normal terminate
res_out = res.communicate()[0]
self.result = res_out