【发布时间】:2014-06-30 11:06:53
【问题描述】:
我想知道,如何获取 Python 脚本中调用的子进程的输出?
from sys import argv
from os.path import exists
from subprocess import call
script, source, target = argv
print "Copying from %s to %s" % (source, target)
indata = open(source).read()
if exists(target):
out_file = open(target, 'w')
out_file.write(indata)
call(["cat", target]) #how can I get text printed on console by cat?
print "OK."
out_file.close()
【问题讨论】:
-
不要使用
call,而是使用check_output。
标签: python subprocess stdout