2015-04-02 3 views

ответ

1

Когда notepad.exe не существует в списке задач, tasklist /fi "imagename eq Notepad.exe" сбрасывает строку «INFO:» на stderr в Windows XP. Вы можете перенаправить stderr на stdout с 2>&1, но проще всего на find /i "notepad".

На боковой ноте вместо if errorlevel 1 вы можете использовать conditional execution.

@echo off 
setlocal 

:loop 

rem // Output nothing for the following code block. 
>NUL 2>NUL (

    rem // Make sure notepad is not running before continuing. 
    tasklist /fi "imagename eq notepad.exe" | find /i "notepad" && (

     rem // Notepad is in tasklist. Sleep 1 second, then check again. 
     timeout /t 1 /nobreak || ping -n 2 localhost 
     goto loop 
    ) 
) 

wordpad.exe 
Смежные вопросы