Python 脚本打开 bash 提示符并终止脚本
我想用 python 编写一个 chroot 包装器。该脚本将复制一些文件,设置一些其他内容,然后执行 chroot,并且应该让我进入 chroot shell。
棘手的部分是我不希望在进入 chroot 后运行任何 python 进程。
换句话说,python 应该完成设置工作,调用 chroot 并终止自身,让我处于 chroot shell 中。当我退出 chroot 时,我应该位于调用 python 脚本时所在的目录中。
这可能吗?
I want to write a chroot wrapper in python. The script will be copying some files, setting up some other stuff and then executing chroot and should land me in a chroot shell.
The tricky part is that I want no python processes running after I am in the chroot.
In other words, python should do the setup work, call chroot and terminate itself, leaving me in a chroot shell. When I exit the chroot, I should be in a directory where I was when I invoked the python script.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的第一个想法是使用
os.exec*
函数。这些将用 chroot 进程(或者您决定使用 exec* 运行的任何进程)替换 Python 进程。
(或类似的东西)
My first thought would be to use one of the
os.exec*
functions. These will replace the Python process with thechroot
process (or whatever you decide to run withexec*
).(or something like that)
或者,您可以为 popen 命令使用一个新线程,以避免阻塞主代码,然后将命令结果传回。
Alternatively, you can use a new thread for the popen command to avoid blocking the main code then pass the command results back.