【发布时间】:2012-05-06 03:01:23
【问题描述】:
下面的命令在 IRB 中有效,但在 Ruby 程序中无效。
DISPLAY=:5 nohup firefox youtube.com &
在irb成功返回:
nohup: redirecting stderr to stdout
当在反引号 ("`") 中从 Ruby 程序调用时,它返回:
** (firefox:12402): WARNING **: Could not connect: Connection refused
** (firefox:12470): CRITICAL **: unable to create '/var/www/.cache/dconf'; dconf will not work properly.
Xlib: extension "RANDR" missing on display ":5".
Failed to stat home directory /var/www: No such file or directory
(firefox:12470): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Failed to connect to socket /tmp/dbus-989cWYOeP6: Connection refused
【问题讨论】:
-
ruby 脚本是否以同一用户身份运行?确保将
/usr/bin/env DISPLAY=:5 nohup ...作为您的命令,以便正确处理环境变量。 -
感谢@d11wtq 的回复。当我使用上面的代码前缀时,我收到了权限被拒绝的消息
-
那么当您在 IRB 中运行代码时,是否与运行 ruby 脚本的用户相同?
-
是的,权限完全不同。 www-data 用户无权连接到 X 会话,或配置了 .Xauthority 文件。你能解释一下你想要达到的目标吗,然后我们可能会想出一个解决方法。通过 Web 请求连接到 Xserver 似乎有点不稳定,并且应该在后台任务中发生。
-
完成。我也给了你一些想法。我们使用不同的工具为您提供不同的方法。