I have the following code snippet as a Python script. I get the proper job output files with no errors. However the stdout
subprocess
log files (i.e. COSMOSIS_output_XXX.txt
etc) don't store the expected runtime logs. Instead, these files have <_io.TextIOWrapper name=9 encoding='UTF-8'>
as the only output written in the files. What is it I am doing wrong?
import subprocess
from subprocess import Popen
jobname = "cosmosis"
arg2 = "output.filename="
Vector = (
" " + ini + " " + arg2 + COSMOSIS_PATH + os.path.splitext(ini)[0] + ".txt"
)
job3 = subprocess.Popen(
["cosmosis" + Vector],
shell=True,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
file = open("%sCOSMOSIS_output_%s.txt" % (ERROR_PATH, ini), "a")
sys.stdout = file
print(job3.stdout)
file_e = open("%sCOSMOSIS_output_ERROR_%s.txt" % (ERROR_PATH, ini), "a")
sys.stdout = file_e
print(job3.stderr)
try:
outs, errs = job3.communicate(timeout=2000)
except TimeoutExpired:
outs, errs = job3.communicate()
job3.kill()
file.close()
file_e.close()