【发布时间】:2018-12-20 19:32:36
【问题描述】:
我使用 Python 开发了一个简单的基于 dbus 的插件 (dbus.service.Object),它从命令行脚本接受 IPC 调用。 dbus 服务配置为在 systemd 中托管。它按预期运行。但是,当我在插件中添加功能以启动 gnome-terminal 时,它失败了。无论是 call() 还是 Popen(),似乎执行都停留在任何这些子进程调用中。想知道如何使插件正确启动 gnome-terminal?
#subprocess.call(['gnome-terminal', '--', '/bin/bash', '-c', 'ls', '-al', '&'])
#subprocess.call(['systemd-run', '--user', '--service-type=forking', 'gnome-terminal', '-t', "Test",'--','/bin/bash', '-c', 'ls', '-al', "&"])
#subprocess.call(['DISPLAY=:0', 'gnome-terminal', '--', '/bin/bash', '-c', 'ls', '-al', '&'])
我还尝试从插件启动 python 脚本并让脚本启动 gnome-terminal 但仍然失败。
Fail 表示终端没有打开,ps 没有显示终端。我也尝试过使用 os.system。如果直接从控制台运行,它就可以工作。
os.system('gnome-terminal -- /bin/bash -c "python /data/scripts/test.a.1.py -f /data/station_profile_A.json"')
日志日志显示以下错误:
12 月 21 日 09:34:20 ubuntu 协调器 [5380]:无法初始化服务器:无法连接:连接被拒绝 Dec 21 09:34:20 ubuntu coordinator[5380]: # Failed to parse arguments: Cannot open display:
如果我在 gnome-terminal 前面添加 'DISPLAY=:0',它没有帮助。
【问题讨论】:
-
“失败”是什么意思?你有例外吗?子进程的 stdout/stderr 是什么?
call()调用是否返回并为您提供退出状态?如果你从一个普通的 Python 程序(不是你的 D-Bus 服务)运行这些调用中的任何一个会发生什么? -
我用更多信息更新了这个问题。谢谢!
标签: python systemd dbus gnome-terminal