This works as it should
set "status="
for /F "usebackq skip=1 tokens=3 delims=," %%H in (`schtasks.exe /fo csv /query /tn "\MS2\Import Process"`) do set "status=%%H"
set status=%status:"=%
echo The Import status: %status%
This says the status is READY
I wanted to check the status every 5 seconds for 1 minute:
for /l %%i in (1, 5, 300) do (
set "status="
for /F "usebackq skip=1 tokens=3 delims=," %%H in (`schtasks.exe /fo csv /query /tn "\MS2\Import Process"`) do set "status=%%H"
set status=%status:"=%
echo The Import status: %status%
timeout /t 5
)
This says the status is always empty
I am using %% notion because I run it in a batch file.
Why doesnt status get set properly in the for loop
Edit: Attempt with delayedexpansion
setlocal EnableDelayedExpansion
for /l %%i in (1, 5, 300) do (
set "status="
for /F "usebackq skip=1 tokens=3 delims=," %%H in (`schtasks.exe /fo csv /query /tn "\MS2\Import Process"`) do set "status=%%H"
echo The Import status: !status!
timeout /t 5
)
It still just says status is empty.
I also get ERROR: The system cannot find the file specified.
just before the echo
I tried putting set "status="
outside the for loop with no avail.