我正在运行下面的Python脚本。当我打印stdout和stderr时,它们会打印成每个字母(请参见下文)。如何让stdout和stderr以每行原始格式打印?
cmd = r"""python ./script.py"""
print cmd
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
output, error = proc.communicate()
for line in output:
print "in stdout"
print line
if 'Onlycloned' in line:
print "OnlyclonedRadars line matched"
#logger.info('OnlyclonedRadars line matched')
radars = line
radarlist = radars.split(':')[1].strip()
#radars = 37142113
for line in error:
print "in stderr"
print line
输出:
in stderr
2
in stderr
0
in stderr
:
in stderr
5
in stderr
8
in stderr
:
in stderr
4
in stderr
5
in stderr
in stderr
r