python脚本怎么开机自动运行?

软件和网站开发以及相关技术探讨
回复
qiudw
帖子: 33
注册时间: 2013-10-21 18:57

python脚本怎么开机自动运行?

#1

帖子 qiudw » 2014-07-11 21:57

比如有一个文件:/home/abc/hello.py,开机后在命令行可以执行:sudo python /home/abc/hello.py,如果要开机自动运行,怎么办呢?
先谢谢各位。
qiudw
帖子: 33
注册时间: 2013-10-21 18:57

python脚本怎么开机自动运行?

#2

帖子 qiudw » 2014-07-11 22:32

比如有一个文件:/home/abc/hello.py,开机后在命令行可以执行:sudo python /home/abc/hello.py,如果要开机自动运行,怎么办呢?
先谢谢各位。
头像
raptorsun
帖子: 25
注册时间: 2008-08-26 23:59

Re: python脚本怎么开机自动运行?

#3

帖子 raptorsun » 2014-07-11 22:49

/etc/init 这个目录下面的脚本都会在启动时执行。 在下面写个脚本包含你想执行的命令就好啦 :)
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: python脚本怎么开机自动运行?

#4

帖子 poloshiao » 2014-07-12 6:29

試試
在 /etc/rc.local
最後一行
exit 0
前面 加上
python /home/abc/hello.py
然後重開機
qiudw
帖子: 33
注册时间: 2013-10-21 18:57

Re: python脚本怎么开机自动运行?

#6

帖子 qiudw » 2014-07-12 20:19

谢谢楼上各位,按照所说方法做好了。
回复