def spawn_process(executable, args, env, outfile=None):
"""Spawn a process using Twisted reactor.
Return a deferred which will be called with process stdout, stderr
and exit code. If outfile is provided then the stdout and stderr
stings will be empty.
Note: this is a variant of landscape.lib.twisted_util.spawn_process
that supports streaming to a file.
"""
list_args = [executable]
list_args.extend(args)
logging.info("running {!r}".format(" ".join(list_args)))
import pprint
logging.info("OS env:\n" + pprint.pformat(env))
result = Deferred()
if outfile is None:
protocol = AllOutputProcessProtocol(result)
else:
protocol = StreamToFileProcessProtocol(result, outfile)
reactor.spawnProcess(protocol, executable, args=list_args, env=env)
return result
评论列表
文章目录