How to run a python script in the background?
Asked Answered
L

6

27

I have a script that checks something on my PC every 5 minutes and I don't want Python to show on my task tray. I use Windows as my operating system.

Is there any way to make Python run in the background and force it to not show in my task tray?

Lisette answered 23/4, 2009 at 21:7 Comment(0)
T
-5

Look for Schedule Tasks in the control panel.

Tati answered 23/4, 2009 at 21:11 Comment(3)
at will pop up my script every X time (or it does'nt ?) I thought about at, but im looking for another way thanksLisette
Task scheduler doesn't allow one to run tasks less than every minute (in case that's of concern)Optometer
Question asks for background, but Task Scheduler runs in foreground by default.Harassed
B
60

If you run a console script using pythonw.exe, it will neither display a window nor appear in the task bar. For example, I use the following command to launch ntlmaps on startup:

C:\BenBlank\Python2.6\pythonw.exe scripts/ntlmaps

Be aware, however, that there is no way to interact with the script, nor to terminate it save via the Task Manager.

Buran answered 23/4, 2009 at 21:15 Comment(3)
This is the best way I've found to run Python applications that use GUI (e.g. with Tkinter).Lashing
Wow, after a decade, this is still the best! ThanksGround
in Windows 10 task manager on the Users task a task called 'python' should be there which you can select and then click the 'End task' buttonDiscontinuance
H
5

Just another option you have:

You can create a shortcut to your Python script, then right-click the shortcut --> Properties --> Shortcut tab

There is a drop-down box under the Run option which lets you run the command minimized.

Hodgkinson answered 23/4, 2009 at 21:17 Comment(1)
The program will still be visible in the taskbar and I think OP didn't want thatJaan
R
3

You could run it as a service. See here

Robbinrobbins answered 1/5, 2009 at 8:7 Comment(0)
A
2

cron it on linux; schedule it on windows [control panel > scheduled tasks > Add scheduled task]

Arthritis answered 23/4, 2009 at 21:10 Comment(1)
Windows scheduler runs it in the foreground; question asks for background. Also, in some versions of windows (e.g. Windows 7) it's under control panel -> administrative tools.Harassed
A
0

To Run python file from any where :

Step 1:

Create Shortcut of Python File.

Step 2:

Place Shortcut in this location  C:\ProgramData\Microsoft\Windows\Start Menu\Programs

Step 3:

Now Right Click --> Go to Properties --> Shortcut --> Press any key on keyboard it will take one shortcut key

Step 4:

Now , Type the Shortcut key which you entered in previous step.

Step 5:

Check out Output!   :)
Avoidance answered 29/6, 2020 at 5:5 Comment(0)
T
-5

Look for Schedule Tasks in the control panel.

Tati answered 23/4, 2009 at 21:11 Comment(3)
at will pop up my script every X time (or it does'nt ?) I thought about at, but im looking for another way thanksLisette
Task scheduler doesn't allow one to run tasks less than every minute (in case that's of concern)Optometer
Question asks for background, but Task Scheduler runs in foreground by default.Harassed

© 2022 - 2024 — McMap. All rights reserved.