1

I have a python script.(For example, test.py)I want to start at 00:00am every day and execute this python script every 15 minutes.

I want to use the bat file to call python script.

How should I write the bat file?

I haven't written a bat file before.

2 Answers2

0

If you want to run you python script every 15mins, perhaps you should consider setting up a scheduled task (the Windows equivalent of cron).

See this question for more info: What is the Windows version of cron?

dukr
  • 26
  • 2
  • I can write scheduled task.But now,I was asked to implement it with bat. –  Dec 22 '17 at 01:48
  • For example,I can write python code "schedule.every().day.at("00:00").do(call_A)",but I was asked to implement it with bat. –  Dec 22 '17 at 01:50
0

One quick implementation for the Python script to run every 15 minutes is to use an infinite loop with 'While'. Instead of relying on a batch file, you can have your python script wait 15 minutes before running again.

    import os, time, sys, datetime

    while True:         # Use WHILE = True for an infinite loop

         timestamp = datetime.datetime.now()

         print('''
                 RUNNING PYTHON SCRIPT EVERY 15 MINUTES
                 PYTHON SCRIPT INITIATED AT %s
               ''' % timestamp)

         # ENTER PYTHON SCRIPT HERE

         print('''
                 PYTHON SCRIPT COMPLETED AT %s
               ''' % timestamp)

         time.sleep(900)  # 900 seconds = 15 minutes before next run
raquino
  • 41
  • 2