Here is the simplest example;
If that window exists, this will print;
Code: Select all
@echo off Set Results= For /f %%A in ('tasklist /nh /v /fi "WINDOWTITLE eq Untitled - Notepad"') do set Results=%%A echo %Results%
However, if it can't find that window, it will print;
INFO: No tasks running with the specified criteria.
ECHO is off.
It prints the Tasklist message directly instead of putting it into %%A. %%A stays empty, so %Results% is also empty.
How is it bypassing the For command, and how do I prevent this so that the error message goes into %%A rather than being printed directly?