在 Python 中执行 *nix 二进制文件

发布于 2024-07-21 02:15:17 字数 322 浏览 1 评论 0原文

我需要运行以下命令:

screen -dmS RealmD top

本质上是在后台调用 GNU 屏幕,会话标题为“RealmD”,并且 top 命令在屏幕内运行。 该命令必须以这种方式调用,因此在重新安装服务器之前,此时无法替代屏幕。 (另一个项目)

我已经在 top 命令中替换了需要运行的服务器二进制文件。 但在为这个 python 模块调试代码时,top 是一个不错的替代品。

我真正需要的是一种在 Python 中使用上述参数执行 screen 的方法。

I need to run the following command:

screen -dmS RealmD top

Essentially invoking GNU screen in the background with the session title 'RealmD' with the top command being run inside screen. The command MUST be invoked this way so there can't be a substitute for screen at this time until the server is re-tooled. (Another project for another time)

I've subbed in the top command for the server binary that needs to run. But top is a decent substitute while the code is being debugged for this python module.

What I really need is a way to execute screen with the above parameters in Python.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖彼岸 2024-07-28 02:15:17

os.system 是最简单的方法,但是,为了获得更多可能性和自由度,还可以查看标准库 subprocess 模块(当然,除非 Stephan202 对 os.system 的简单使用能够满足您的所有需求;-) 。

编辑这是os.system()的标准替换

p = Popen("screen -dmS RealmD top", shell=True)
sts = p.wait()

http://docs.python.org/library/subprocess.html#replacing-os-system

os.system is the simplest way, but, for many more possibilities and degrees of freedom, also look at the standard library subprocess module (unless Stephan202's wonderfully simple use of os.system meets all your needs, of course;-).

Edit Here's the standard replacement for os.system()

p = Popen("screen -dmS RealmD top", shell=True)
sts = p.wait()

http://docs.python.org/library/subprocess.html#replacing-os-system

夜巴黎 2024-07-28 02:15:17

使用 os.system

os.system("screen -dmS RealmD top")

然后在一个单独的 shell 中你可以拥有通过运行 screen -rd RealmD 查看 top

Use os.system:

os.system("screen -dmS RealmD top")

Then in a separate shell you can have a look at top by running screen -rd RealmD.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文