fix there is no error log when run in subprocess (#179)

fix there is no error log when run in subprocess
for/master
Cathy0908 2022-09-02 17:23:15 +08:00 committed by GitHub
parent 80ca821518
commit bcfb11e893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -70,7 +70,7 @@ def run_in_subprocess(cmd):
try: try:
with subprocess.Popen( with subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) as return_info: stderr=subprocess.PIPE) as return_info:
while True: while True:
next_line = return_info.stdout.readline() next_line = return_info.stdout.readline()
return_line = next_line.decode('utf-8', 'ignore').strip() return_line = next_line.decode('utf-8', 'ignore').strip()
@ -79,9 +79,19 @@ def run_in_subprocess(cmd):
if return_line != '': if return_line != '':
logging.info(return_line) logging.info(return_line)
err_lines = ''
while True:
next_line = return_info.stderr.readline()
return_line = next_line.decode('utf-8', 'ignore').strip()
if return_line == '' and return_info.poll() != None:
break
if return_line != '':
logging.info(return_line)
err_lines += return_line + '\n'
return_code = return_info.wait() return_code = return_info.wait()
if return_code: if return_code:
raise subprocess.CalledProcessError(return_code, return_info) raise RuntimeError(err_lines)
except Exception as e: except Exception as e:
raise e raise e