简体   繁体   English

如何在每 5 分钟 using.bat 文件后关闭并重新运行 python exe

[英]How to close and rerun a python exe after every 5min using .bat file

Hey Guy I am running a socket code which is written in python and due to some reasons i need to rerun it after every 5 min some one suggested me to use task scheduler i tried, but it was not running so I searched and found a script which runs the program after every 5 min in.exe format.嘿,伙计,我正在运行一个用 python 编写的套接字代码,由于某些原因,我需要在每 5 分钟后重新运行一次,有人建议我使用我尝试过的任务调度程序,但它没有运行,所以我搜索并找到了一个脚本每 5 分钟运行一次程序 in.exe 格式。 Now main problem is, it opens a new window and old window is still open.现在主要问题是,它打开了一个新的 window 而旧的 window 仍然打开。 for eg: when I run the program it open in 1 number window.例如:当我运行程序时,它在 1 个数字 window 中打开。 After 5 min it opens 2 number window in which program is running but due to it is socket programming it is connected to 1 number window. 5分钟后,它打开2个号码window,程序正在其中运行,但由于它是套接字编程,它连接到1个号码window。 Now I want to close 1 number window so that the socket may get connect to 2 number window.现在我想关闭 1 个号码 window 以便套接字可以连接到 2 个号码 window。

I think it is a shell window and program is in.bat format.我认为它是 shell window 并且程序是 in.bat 格式。

The code is:代码是:

:loop
@echo off
start python "python program location" 
timeout /t 300 /nobreak
exit0
goto :loop

The line "@echo off" and "exit0" was suggested in some articles but the are not working.在一些文章中建议使用“@echo off”和“exit0”行,但它们不起作用。 "300" is time in sec of 5 min “300”是以 5 分钟为单位的时间

Give the window a title, then kill it before starting the new one.给 window 一个标题,然后在开始新的之前杀死它。 Here we are giving it a title name of MyScript and we're also just killing it by that name:在这里,我们给它命名为MyScript ,我们也只是用这个名字杀死它:

@echo off
:loop
start "MyScript" python "python program location" 
timeout /t 300 /nobreak
taskkill /FI "WINDOWTITLE eq MyScript"
goto :loop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 celery/cronjobs 每 5 分钟在数据库中添加一个用户 - How to add a user in database in every 5min using celery/cronjobs Python For循环列表,每5分钟运行一次 - Python For Loop List, Function Every 5min 对每 5 分钟的值进行分组和求和 / 用字符串值重新采样 5 分钟的数据 - Grouping and sum the value for every 5min / resampling the data for 5min with string values 如何在python中打开一个exe文件并继续而不关闭exe文件? - How to open an exe file in python and continue without close exe file? 如何创建在5分钟间隔内每1分钟发送一次大型电子邮件和小型电子邮件的循环 - How do I create this loop of sending large email and small email every 1min within a 5min interval Python 文件 .exe 只出现片刻,然后立即关闭 - Python file .exe just appear in a moment and close immediately after that Python如何在停止后重新运行代码 - Python how to rerun code after it stops 在Windows中使用Python打开文件后如何关闭cmd? - How to close cmd after opening a file using Python in Windows? 我的.bat文件在使用`python`后将无法读取这些行 - My .bat file wont read the lines after using `python` 给定时间在 python pandas 中获取 5 分钟范围内的行 - given time get rows within 5min range in python pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM