简体   繁体   中英

How to make a looping BAT script run in the background in Windows 10?

I have it running a python script in a loop:

@ECHO OFF 

:loop
D:\Python\python.exe C:\pythonfile.py

goto loop
PAUSE

How do I make it so when I double-click the batch file, the process runs in the background and the console window isn't showing in the taskbar?

Make the process be hidden completely with windows built in vbs, then call the batch from it. You will then run the vbs file instead of the batch, which will call the batch file.

no_see.vbs

Set MyScript    = CreateObject("WScript.Shell")
MyScript.Run "C:\wherever\script\is\batchfile.cmd", 0, False

This will run the batch file completely hidden.

The python script however might still call a console window, so you should consider this.

@ECHO OFF
:loop
D:\Python\pythonw.exe C:\pythonfile.pyw
goto loop
PAUSE

This will run without a console, meaning everything will be hidden.

One concern I have, you are running the .py file in a loop, no sleep nothing meaning you will spawn thousands of python instances. What exactly are you attemping? If you can give me an idea, I can perhaps help in making the solution better.

I'm not sure if there is a way to do that using batch, at least not one that I know of. However, I would recommend doing this with a scheduled task instead if you do not want it running in the taskbar.

Open the Task Scheduler and in the library, create a new task. From there, you can set conditions, triggers, and plenty of other options for how you want it to run, including automatic start at logon, etc.

Just thought of this...alternatively, you could also use the Task View of Windows 10. Open and run the batch file, and then move it to another virtual desktop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM