我找了網路教學,寫一個bat內容
sc query mysql
for /F %%i in ('sc query mysql') ^
do (
echo %%i
)
輸出結果
SERVICE_NAME: mysql
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1067 (0x42b)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
SERVICE_NAME:
TYPE
STATE
WIN32_EXIT_CODE
SERVICE_EXIT_CODE
CHECKPOINT
WAIT_HINT
結果,只能獲取key,像TYPE,STATE等等,請教如何處理才可以獲取KEY對應的VALUE,像STATE=1 STOPPED ?
替你問Claude.ai
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:" %%a in ('sc query mysql ^| findstr "STATE"') do (
set "state=%%b"
set "state=!state:~1!"
for /f "tokens=1,2 delims= " %%c in ("!state!") do (
echo STATE: %%c %%d
)
)