Python 脚本在启动时启动 [英] Python script start on boot
问题描述
我正在制作一个简单的 python 脚本,作为在后台运行的可执行文件.有没有办法让它在启动时运行?我知道我可以将可执行文件添加到 Startup 目录,但这需要我根据我的机器对其进行硬编码.我希望它也能在其他机器上运行(windows 和 ubuntu).我将如何处理这个问题?谢谢!
I'm making a simple python script to run as an executable that runs in the background. Is there a way to make it run on startup? I know that I could add the executable to the Startup directory but that would require me to hard code it according to my machine. I would like it to work on other machines as well (windows and ubuntu). How would I approach this issue? Thanks!
推荐答案
在 Linux 中,您可以将其添加到您的 cron 中:crontab -e
In Linux you can add it to your cron: crontab -e
@reboot python /home/user/myscript.py
(@reboot 用于重启和启动)
(@reboot is for reboots and startups)
在 Windows 中,您可以使用任务计划程序并将触发者"定义为启动.见创建基本任务"红框.
In Windows you can use the Task Scheduler and define the "triggered by" as Startup. See the red box for "Create basic task".
在程序/脚本字段中,您应该输入:
In the Program/script field, you should enter:
C:\Python27\python.exe
在添加参数中,您应该输入:
And in the add arguments, you should enter:
"C:\My script.py"
阅读此处了解更多信息详细信息并查看下面的屏幕截图...
Read here for more details and see screenshots below...
这篇关于Python 脚本在启动时启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!