China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-07 03:46
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question about using if in a batch file View 824 Replies 2
Original Poster Posted 2007-12-28 14:41 ·  日本 IIJ
新手上路
Credits 16
Posts 8
Joined 2007-04-12 07:00
19-year member
UID 84846
Gender Male
Status Offline
Hello everyone,
I want to create a batch file to automatically check all programs in the process list. If a certain process is found, it exits automatically; if a certain process is not found, then pop up a dialog box to tell the user that the process is not running. How can this be done?
Could you please help me? Thanks.
Floor 2 Posted 2007-12-28 15:39 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
@echo off
set DstProc=notepad.exe

tasklist | findstr /i "%DstProc%">nul
if %errorlevel% neq 0 (
echo The process is not running: %DstProc%
)
Floor 3 Posted 2007-12-28 15:57 ·  日本 IIJ
新手上路
Credits 16
Posts 8
Joined 2007-04-12 07:00
19-year member
UID 84846
Gender Male
Status Offline
Sorry, but when I run it there is no response at all. Could it be because the text format got messed up when I COPYed it??
Forum Jump: