@echo off
set "TARGET_PROGRAM=重启程序路径"
set port=需要监听端口
:loop
REM
powershell -Command "$ErrorActionPreference = 'Stop'; $result = Test-NetConnection -ComputerName localhost -Port %port%; if ($result.TcpTestSucceeded) { exit 0 } else { exit 1 }"
REM
if %errorlevel% equ 0 (
echo 1111111
) else (
echo 3333333333
start "" "%TARGET_PROGRAM%"
timeout 5 >nul
)
REM
timeout 10 >nul
goto :loop REM
:eof
REM
window环境下监听端口重启程序脚本
于 2024-04-16 10:10:32 首次发布