当前位置: 动力学知识库 > 问答 > 编程问答 >

cmd - Checking for several different exe's running with a batch file

问题描述:

So currently I'm using:

 :METFEXTLOOP1

tasklist | find /i "Full_Index_Update.exe" >nul 2>&1

IF ERRORLEVEL 1 (

GOTO METFEXTLOOP2

) ELSE (

ECHO The Full Index Update is Running...

ping localhost -n 3 >nul

cls

GOTO METFEXTLOOP1

)

::Verify Early Index Update Is not Running

:METFEXTLOOP2

tasklist | find /i "Early_Index_Update.exe" >nul 2>&1

IF ERRORLEVEL 1 (

GOTO METFEXTLOOP3

) ELSE (

ECHO The Early Index Update is Running...

ping localhost -n 3 >nul

cls

GOTO METFEXTLOOP2

)

::Verify Morningstar US Mutual Funds Extended is not Running

:METFEXTLOOP3

tasklist | find /i "MstarExt.exe" >nul 2>&1

IF ERRORLEVEL 1 (

GOTO METFEXTLOOP4

) ELSE (

ECHO The Morningstar US Mutual Funds Extended Update is Running...

ping localhost -n 3 >nul

cls

GOTO METFEXTLOOP3

)

:METFEXTLOOP4

ECHO Hello World

pause

And that works fine, but what I'd like to do is consolidate it more, since this check is performed after each additional update is being run. I thought I was being clever with:

 @ECHO OFF

:FullLOOP

tasklist | find /i "SA_8.5_Setup.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "Early Index.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "MorningstarUSMutualFundsBasic.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "MorningstarUSMoneyMarketFundsBasic.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "MorningstarETFBasic.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "MorningstarUSMutualFundsExtended.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "LipperUSMutualFundsExtended.exee" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "LipperUSMutualFundsBasic.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "LipperUSMutualFundsBasic.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "PSNExtended.exe" >nul 2>&1

IF ERRORLEVEL 1 (

tasklist | find /i "PSNBasic.exe" >nul 2>&1

GOTO Proceed

) ELSE (

ECHO Another installer is running....

ping localhost -n 3 >nul

cls

GOTO FullLOOP

)

:Proceed

cls

ECHO Hello World

pause

However this crashes almost immediately. Is there a "cheating" way of doing this? Or do I need to do multiple loops in order to make these checks. This is probably a dumb and obvious mistake on my part. However any assistance with this would be very welcome and appreciated.

网友答案:

I hope this helps.

@echo off
:FullLOOP
tasklist /FI "IMAGENAME eq SA_8.5_Setup.exe" 2>NUL | find /I /N "SA_8.5_Setup.exe">NUL
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq Early Index.exe" 2>NUL | find /I /N "Early Index.exe">NUL
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq MorningstarUSMutualFundsBasic.exe" 2>NUL | find /I /N "Early MorningstarUSMutualFundsBasic.exe">NUL 
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq MorningstarUSMutualFundsBasic.exe" 2>NUL | find /I /N "MorningstarUSMutualFundsBasic.exe">NUL 
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq MorningstarUSMoneyMarketFundsBasic.exe" 2>NUL | find /I /N "MorningstarUSMoneyMarketFundsBasic.exe">NUL
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq MorningstarETFBasic.exe" 2>NUL | find /I /N "MorningstarETFBasic.exe">NUL
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq MorningstarUSMutualFundsExtended.exe" 2>NUL | find /I /N "MorningstarUSMutualFundsExtended.exe">NUL
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq LipperUSMutualFundsExtended.exe" 2>NUL | find /I /N "LipperUSMutualFundsExtended.exee">NUL
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq LipperUSMutualFundsBasic.exe" 2>NUL | find /I /N "LipperUSMutualFundsBasic.exe">NUL
if "%ERRORLEVEL%"=="1" ( tasklist /FI "IMAGENAME eq PSNExtended.exe" 2>NUL | find /I /N "PSNExtended.exe">NUL
if "%ERRORLEVEL%"=="1" ( 
tasklist /FI "IMAGENAME eq PSNBasic.exe" 2>NUL | find /I /N "PSNBasic.exe">NUL
GOTO Proceed
)))))))))) else (
                    ECHO Another installer is running....
                    ping localhost -n 3 >nul    cls
                    GOTO FullLOOP
                    )
pause
    :Proceed
    cls
    ECHO Hello World
    pause
分享给朋友:
您可能感兴趣的文章:
随机阅读: