windows:程序异常退出之后就自动重启

@echo off
title 监控并重启程序
:en
tasklist |find "test_camera.exe"||start C:\Users\admin\source\repos\smoke_monitor\test_camera.exe
ping -n 20 127.0.0.1>nul
goto en

如何找路径:

echo 目录中有空格也可以加入""避免找不到路径

@echo off

echo 获取的当前盘符是:"%~d0"

echo 当前盘符和路径:"%~dp0"

echo 当前批处理全路径:"%~f0"

pause

在这里插入图片描述

综上,应该这样写:

@echo off
title auto_restart.bat
:en
echo "%~dp0"
tasklist |find "test_camera.exe"|| start /d "%~dp0" test_camera.exe
ping -n 20 127.0.0.1>nul
goto en