我不能从一个将特权留给普通用户的sudoed 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。你觉得怎么样?