def run_command_inline(argv, funct, *args, **kwargs):
argv_save = sys.argv
environ_save = EnvironmentSnapshot()
captured_stdout = StringIO()
captured_stderr = StringIO()
sys.argv = argv
exitcode = None
with redirect_stdout(captured_stdout):
with redirect_stderr(captured_stderr):
try:
exitcode = funct(*args, **kwargs)
except SystemExit as e:
exitcode = e.code
finally:
# restore environment, command-line arguments, and the native
# modules system
environ_save.load()
sys.argv = argv_save
fixtures.init_native_modules_system()
return (exitcode,
captured_stdout.getvalue(),
captured_stderr.getvalue())
评论列表
文章目录