Skip to content

Latest commit

 

History

History
88 lines (45 loc) · 1.63 KB

python.md

File metadata and controls

88 lines (45 loc) · 1.63 KB

Running Python scripts with SvcBatch

Python scripts can be run as Windows services using SvcBatch.

You can either use the simple batch file that will launch your Python interpreter and actual Python script, or use Python interpreter directly.

Prerequisites

Install or download your favorite Python distribution and svcbatch.exe binary release (or build it from the source code) The example depends on Python3 functionality, but the code can be modified.

Python script

Inside python directory you can find a simple python script that runs as infinite loop and prints current time each five seconds.

Wrapper batch file

Inside python directory you can find a simple python batch file that calls the python interpreter.

Installation

Service installation and management tasks are done by using SvcBatch or Windows SC utility.


> svcbatch create pyservice

... or

> sc create pyservice binPath= ""%CD%\svcbatch.exe" pyservice.bat"

To create a service that will use python.exe directly without cmd.exe's wrapper pyservice.bat file, use the following:


> svcbatch create pyservice --set Command python --set Environment PATH=@ProgramFiles@\Python311;$PATH pyservice.py


Service management

After installation you can use SvcBatch to start or stop the service. To manually start the service using SvcBatch, type:


> svcbatch start pyservice

To stop the service, type


> svcbatch stop pyservice

To delete the service, type


> svcbatch delete pyservice