I am creating a script to check if my Minecraft server is running or not, but My script never works. Note: I'm not that good at Bach script coding I am using Win 10 Pro
I've looked online and found this
echo %~1
tasklist /FI "IMAGENAME eq Cave SMP Vanilla 1.19.3" /FO CSV > search.log
FINDSTR Cave SMP Vanilla 1.19.3 search.log > found.log
FOR /F %%A IN (found.log) DO IF %%~zA EQU 0 GOTO end
echo server off
:end
echo server on
del search.log
del found.log
pause
but it just outputs enter image description here (The server is currently running) I expect it to output server is on
I hope someone can help me! Thanks Alot!!!!!
Please try this. There is notepad.exe
as Image Name instead of your Cave SMP Vanilla 1.19.3
. You can try to replace notepad.exe
and check if it works for you.
@echo OFF
TASKLIST /FI "IMAGENAME eq notepad.exe" /FO CSV > search.log
FINDSTR /R /C:"notepad.exe" search.log > found.log
FOR /F %%A IN (found.log) DO (
IF %%~zA EQU 0 (
GOTO :end )
)
echo server off
GOTO :end_file
:end
echo server on
:end_file
del search.log
del found.log
pause
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.