看一下Python的子进程模块,您可以捕获变量的输出,然后使用它。有办法拦截steer和stout。它从2.4版开始就可以使用了。我用它来编写运行系统命令的脚本来捕获工作中的输出。回答如果你需要一个例子,我可以从我的工作电脑明天上午挖一个。。。在try:

# Needs to all be one argument for acme command...
cmd = ["acme nw -proj " + self.based_on]
p = subprocess.Popen(cmd,
cwd=place,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, error_msgs = p.communicate()
except (OSError) as err:
sys.stdout.write("ERROR {0} ({1})\n".format(err.strerror,
err.errno))
sys.exit(err.errno)
if len(error_msgs) > 0 and error_msgs != "Scanning the source base and preparing the workspace, please wait ...\n":
sys.stdout.write("There were errors, during view create\n")
sys.stdout.write(error_msgs)
else:
sys.stdout.write("SUCCESS\n")