In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to use python script to trigger .bat file in Windows". The content in the article is simple and clear, easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "how to use python script to trigger .bat file in Windows".
Catalogue
Run the Python script: .bat file
Python script
Experience in bat operation
Trigger the .bat file regularly in Windows
Run the Python script: .bat file
In Windows, .bat files are batch files, much like .sh (shell) files in Linux.
If we want to run a Python script in Windows, we can first go to the directory where the python file is located through CMD, and then run it.
But this is troublesome, every time you have to open CMD, enter the folder, and run the file.
Therefore, in order not to re-enter every time, it is recommended that the code be written in a txt file. After writing, just change the suffix of the txt file to .bat, and then double-click to run it.
Cd C:\ Users\ Season\ Desktop\ python timer.pypython script import threadingimport datetimeimport timedef hello (RUNTIME): print ("execute once...") Global timer timer = threading.Timer (RUNTIME, hello, [RUNTIME,]) timer.start () if _ _ name__ = = "_ _ main__": print ("now {}" .format (datetime.datetime.now ()) year = int (time.strftime ('% Yee, time.localtime ()) month = int (time.strftime ('% masked, time.localtime ()) day = int (time.strftime ('% d')) Time.localtime ()) + 1 hour = int (time.strftime ('% hags, time.localtime () minute = int (time.strftime ('% time.localtime () myruntime = datetime.datetime (year,month,day,hour,minute,0) RUNTIME = 24060mm 60 print ("{} run" .format (myruntime)) timer = threading.Timer (RUNTIME, hello, [RUNTIME,]) timer.start () bat operation experience
The first run failed because the path could not be recognized in Chinese
After changing the path to pure English, the second run was successful.
Tip: it is recommended to use an absolute path, and the path is pure English.
Trigger the .bat file regularly in Windows
In Windows, follow these steps to trigger the job:
1. Right-click my computer
two。 Select "Manage/ Management" and the following window pops up
3. Select System Tools/ system tools-Task Scheduler/ Task Scheduler-Task Scheduler Library/ Task Scheduler Library
4. Click "Create Basic Task/ create a basic task" in the Action column on the right to create a basic task
5. Fill in the name and description of the task and write it down casually. Click next.
6. Select the frequency and specific time of the task
7. The operation is to start the program
8. Click "Browse..." , select the .bat file we want to run
9. Then the next step is Finish.
10. Return to the Task Scheduler Library to view your tasks.
Thank you for your reading, the above is the content of "how to use python script to trigger .bat file in Windows". After the study of this article, I believe you have a deeper understanding of how to use python script to trigger .bat file in Windows. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.