def _run_single_command(cmd):
"""Run a single command inside the virtual environment
"""
builtins = __builtins__
# this is how the python -c command works
sys.argv.insert(0, "-c")
import __main__
__main__.__dict__.clear()
__main__.__dict__.update(dict(
__name__ = "__main__",
# file is not defined when 'python -c "print(__file__)"' is run
#__file__ = script_file,
__builtins__ = builtins
))
globals = __main__.__dict__
locals = globals
code = compile(cmd, "<string>", "single")
exec code in globals, locals
评论列表
文章目录