[英]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.