Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ubuntu在使用Firefox的系统启动时运行python脚本_Python_Linux_Shell_Ubuntu_Firefox - Fatal编程技术网

Ubuntu在使用Firefox的系统启动时运行python脚本

Ubuntu在使用Firefox的系统启动时运行python脚本,python,linux,shell,ubuntu,firefox,Python,Linux,Shell,Ubuntu,Firefox,我编写了python脚本,它使用subprocess.pOpen()模块来运行和操作两个GUI程序:Firefox和VLC player。我正在桌面模式下使用Ubuntu14.04LTS操作系统 我的问题是,当我试图在系统启动时运行python脚本时,脚本正在运行,但Firefox或VLC没有启动 到目前为止,我尝试使用shell脚本来运行python脚本,然后使用crontab和@reboot/home/user/startup.sh来执行python脚本。我为正在使用的每个脚本设置了所有权限

我编写了python脚本,它使用
subprocess.pOpen()
模块来运行和操作两个GUI程序:Firefox和VLC player。我正在桌面模式下使用Ubuntu14.04LTS操作系统

我的问题是,当我试图在系统启动时运行python脚本时,脚本正在运行,但Firefox或VLC没有启动

到目前为止,我尝试使用shell脚本来运行python脚本,然后使用
crontab
@reboot/home/user/startup.sh
来执行python脚本。我为正在使用的每个脚本设置了所有权限。我给了我的用户根权限,所以一切都可以

我还尝试在
/etc/rc.local
文件中运行脚本放置命令
“sudopython/path/to/my/script.py”
,但这也没有帮助

我在谷歌上搜索发现有人在使用他们放在
~/.config/autostart/
目录下的
.desktop
文件,但也失败了。我写的例子:

[Desktop Entry]
Type=Application
Exec="sudo python /home/user/path_to_my_script/my_script.py"
X-GNOME-Autostart-enabled=true
Name=screensplayer
Comment=screensplayer

我在
~/.config/autostart/
目录中将其保存为
program.desktop
,但它不起作用。我确信有办法解决这个问题,但不知道如何解决。任何帮助都将不胜感激

找到了解决我问题的方法。在python中使用
pOpen
运行命令时,如下所示:

FNULL = open(os.devnull, 'w')
_FIREFOX_START = ["sudo", "firefox", "test.com/index.html"]
subprocess.Popen(self._FIREFOX_START, stdout=self.FNULL, stderr=subprocess.STDOUT)
python /home/user/path_to_script/script.py
它不会运行应用程序,因为“
sudo
”这个词,当我删除它时,它工作了

还要在终端中运行gnome会话属性并添加新的启动应用程序,请注意,您必须在没有sudo的情况下执行python脚本,如下所示:

FNULL = open(os.devnull, 'w')
_FIREFOX_START = ["sudo", "firefox", "test.com/index.html"]
subprocess.Popen(self._FIREFOX_START, stdout=self.FNULL, stderr=subprocess.STDOUT)
python /home/user/path_to_script/script.py

此外,我还授予了我的用户root权限,以便kepp记住这一点。

找到了解决我问题的方法。在python中使用
pOpen
运行命令时,如下所示:

FNULL = open(os.devnull, 'w')
_FIREFOX_START = ["sudo", "firefox", "test.com/index.html"]
subprocess.Popen(self._FIREFOX_START, stdout=self.FNULL, stderr=subprocess.STDOUT)
python /home/user/path_to_script/script.py
它不会运行应用程序,因为“
sudo
”这个词,当我删除它时,它工作了

还要在终端中运行gnome会话属性并添加新的启动应用程序,请注意,您必须在没有sudo的情况下执行python脚本,如下所示:

FNULL = open(os.devnull, 'w')
_FIREFOX_START = ["sudo", "firefox", "test.com/index.html"]
subprocess.Popen(self._FIREFOX_START, stdout=self.FNULL, stderr=subprocess.STDOUT)
python /home/user/path_to_script/script.py
此外,我还授予了我的用户root权限,以便kepp记住这一点