批处理脚本 - 检查和终止进程

时间:2017-11-23 21:53:18

标签: windows batch-file

我想要编写批处理脚本:

  1. 打开cmd.exe然后运行运行最小化Matlab(MATLAB.exe)然后运行matlab应用程序(MATLABWindow.exe)的命令
  2. 之后必须检查Matlab应用程序是否正常工作
  3. 如果是,则不做任何事(仍在检查)
  4. 如果没有,它将杀死最小化的MATLAB.exe
  5. 我写的但除了运行matlab和matlab app之外没有用:

    @ECHO OFF
    START cmd.exe /min /k "matlab -nosplash -nodesktop -minimize -r "matlab.apputil.run('ThorlabsLC100APP')""
    taskkill /F /IM cmd.exe
    
    SLEEP 30
    
    :search
    TASKLIST|FIND "MATLABWindow.exe"
    IF %ERRORLEVEL% equ 0 (
    GOTO search)
    ELSE (GOTO found)
    TIMEOUT /T 5
    GOTO search
    
    :found
    taskkill /im MATLAB.exe
    
    EXIT
    

    由于

1 个答案:

答案 0 :(得分:0)

解决:

if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0"  %* && exit
@ECHO OFF
START /min cmd.exe /k "matlab -nosplash -nodesktop -minimize -r "matlab.apputil.run('ThorlabsLC100APP')""


timeout /t 30 /nobreak


:loop
tasklist /FI "IMAGENAME eq MATLABWindow.exe" | findstr "MATLABWindow.exe" >nul
if %ERRORLEVEL% == 1 goto mycode
goto loop

:mycode

taskkill /F /IM MATLAB.exe
taskkill /F /IM cmd.exe

end