user2278298
user2278298

Reputation: 47

Python script start on boot

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!

Upvotes: 1

Views: 1391

Answers (1)

philshem
philshem

Reputation: 25331

In Linux you can add it to your cron: crontab -e

@reboot python /home/user/myscript.py

(@reboot is for reboots and startups)

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...

enter image description here

enter image description here

enter image description here

Upvotes: 3

Related Questions