php - 从其他用户那里获取节奏盒信息

标签 php python c dbus rhythmbox

我在桌面上运行了Rhythmbox,我希望能够通过web界面远程控制它。但是,我在访问它时遇到问题,因为rhythmbox-client抱怨试图访问它的用户(www data)没有a)正在运行as X会话,b)没有访问rhythmbox dbus信息的权限。
(rhythmbox-client:13954): Rhythmbox-WARNING **: /bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
我在ubuntu 10.04上运行apache和php。通过从不同的用户通过php cli调用php脚本,也尝试了以下方法(使用不同的用户进入我自己的框)
我试过这些方法:
从php脚本中调用system()和exec(),其中包含“rhythmbox client--print playing--no start--no resent”
在php中直接使用DBus以及python脚本(使用system()/exec()从php脚本调用它)
在C程序中使用setuid()setruid()seteuid()并通过php调用它。
我现在不知所措。这可能吗?
[编辑]
我使用了@IvanGoneKrazy的建议,并从this similar question中获取了环境代码。现在,我得到了带有以下错误消息的代码:

import subprocess, os

p = subprocess.Popen('dbus-launch', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for var in p.stdout:
  sp = var.split('=', 1)
  os.environ[sp[0]] = sp[1][:-1]

os.system('rhythmbox-client --print-playing')

错误消息:
(rhythmbox-client:15377): Rhythmbox-WARNING **: Launch helper exited with unknown return code 1

最佳答案

给出了一个类似的问题和Python解决方案。根本问题似乎是system()和exec()没有设置正确的环境变量。您可以使用PHPshere为PHP生成的进程设置环境变量。

关于php - 从其他用户那里获取节奏盒信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3784340/

相关文章:

php - 如何在 isset_POST 中设置 OR

python - PyQt/PySide 中是否需要 deleteLater()?

python - ZeroMQ 管道模式

python - 导入 Bazel 构建 Tensorflow

关于 if 语句和 strcmp 与字符串的混淆

c - 从字节数组中扫描字符串

c++ - UTF-8 表示形式和 unicode 表示形式之间的字符串转换

php - 在多个sql表中选择一个名称

php - 通过 postgres 中的单个查询访问一组值

php - 为什么在我的网站上,PHP 不是在 FF 中解释,而是在 Chrome 中解释?