下面的命令在IRB中工作,但不能在Ruby程序內工作。爲什麼我的命令在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
感謝您的回覆@ d11wtq。當我以 – Dru
以上的代碼作爲前綴時,我收到了權限被拒絕的消息。因此,當您在IRB中運行代碼時,它與ruby腳本運行時的用戶相同? – d11wtq