0
普通のユーザーに特権を与えるsudoされたpythonスクリプトからfirefoxを実行できません。私が書く場合特権を持つrootで実行されたスクリプトからPythonがFirefoxを実行できない
$ sudo python >>> import os >>> import pwd, grp >>> uid = pwd.getpwnam('norby')[2] >>> gid = grp.getgrnam('norby')[2] >>> os.setegid(gid) >>> os.seteuid(uid) >>> import webbrowser >>> webbrowser.get('firefox').open('www.google.it') True >>> # It returns true but doesn't work >>> from subprocess import Popen,PIPE >>> p = Popen('firefox www.google.it', shell=True,stdout=PIPE,stderr=PIPE) >>> # Doesn't execute the command >>> You shouldn't really run Iceweasel through sudo WITHOUT the -H option. Continuing as if you used the -H option. No protocol specified Error: cannot open display: :0
私はそれがpythonの問題ではないと思うが、firefox/iceweasel/debian構成の問題だと思う。たぶんfirefox UIDとEUIDではなく、UIDが0なのでプロセスが実行されません。あなたはどう思いますか?
Popenでxtermを起動してみます。これはDISPLAY/xauthの問題かもしれません。 – abbot
xtermは動作しますが、firefoxは動作しません – Emilio