def run(command, fail_on_error=False, interactively=False):
child = pexpect.spawn('/bin/sh', ['-c', command], echo=False)
child.logfile_read = StringIO.StringIO()
child.logfile_send = StringIO.StringIO()
if not interactively:
child.expect(pexpect.EOF)
if fail_on_error and child.exitstatus > 0:
raise Exception(
'%s (exit code %s)' % (
child.logfile_read.getvalue(),
child.exitstatus
)
)
return {
'child': child,
}
评论列表
文章目录