1

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!

1
  • Afaik, launching a program at startup (startup of the machine, or login?) depends on the OS. So you will have to hardcode at least that part. You could ask this question (which is essentially unrelated to Python) in the respective StackExchange sites (there's askubuntu and probably one for Windows). Commented Mar 13, 2014 at 15:45

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

If anyone finds it useful pythonw.exe runs the python script without opening a console window (source).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.