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-13 02:29
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » How to tell in a batch file whether a program is already running? View 1,179 Replies 5
Original Poster Posted 2003-09-02 00:00 ·  中国 安徽 六安 霍山县 电信
初级用户
Credits 175
Posts 22
Joined 2003-07-24 00:00
23-year member
UID 7466
Gender Male
Status Offline
I want to write a batch file. It takes several parameters; some of them are standalone items, while some others must be run only after UCDOS is running. That creates a problem: if I put
\ucdos\rd16
\ucdos\knl
at the front, then those items that don't need UCDOS will also have to be run only after UCDOS is running, which is annoying. If I don't put UCDOS at the front, then those programs that must run under UCDOS will each need to have \ucdos\rd16 ; \ucdos\knl added to them. That's somewhat repetitive and cumbersome. And those items will end up starting UCDOS repeatedly, even though starting UCDOS once is enough.
Is there any good way to solve this?
Can I make a check in the batch file to determine whether UCDOS is already running?
Floor 2 Posted 2003-09-03 00:00 ·  中国 河南 驻马店 联通
金牌会员
★★★★
龙哥DOS
Credits 4,289
Posts 1,501
Joined 2003-02-23 00:00
23-year member
UID 983
Gender Male
From 河南省
Status Offline
Although I'm not very good at batch files, I can give you some programming ideas. You can create a temporary file as a marker when it runs, and then do a conditional check where needed so that different actions are carried out.
C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++
C++ ☆☆☆ 中国DOS联盟成员 ☆☆☆ C++
C++ ★★★ 爱提问的红色狂想 ★★★ C++
C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++
Floor 3 Posted 2003-09-06 00:00 ·  中国 山东 烟台 福山区 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re daiddcc:

What you're asking isn't very clear. From what I understand, you want to mix together program items that don't need UCDOS and ones that do, but you find the frequent switching of UCDOS on and off troublesome.

First, let's analyze the problem. To avoid the code redundancy caused by frequently switching UCDOS on and off, you can write the UCDOS startup/shutdown code as a separate batch file, then use call directly before and after program items that need UCDOS. If you want to avoid redundancy in the execution process, then it depends on the specific situation. First separate the program items that need UCDOS from those that don't, then put them into two large modules. In the UCDOS module, start UCDOS first, then according to the parameter switch jump to the specific module that needs to be executed.

Also, to determine whether UCDOS is already running, you can register an environment variable, which is usually a bit better than creating a temporary file:

::ucdos.bat
@echo off
\ucdos\rd16
\ucdos\knl
set ucdos=load

::application
@echo off
if "%ucdos%"=="" call ucdos.bat
if "%ucdos%"=="load" goto program that needs UCDOS or UCDOS unload label
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 4 Posted 2003-09-06 00:00 ·  中国 福建 福州 电信
元老会员
★★★
农民
Credits 2,903
Posts 991
Joined 2003-07-23 00:00
23-year member
UID 7391
Gender Male
From 福建省
Status Offline
The method from the poster above is very practical!
艰难奋长戟,万古用一夫

中国DOS联盟 http://www.cn-dos.net 欢迎大家来共同学习
我的MSN&E-Mail cn_archer@hotmail.com QQ 56049418
Floor 5 Posted 2003-09-09 00:00 ·  中国 广东 广州 华南理工大学教育网
初级用户
Credits 112
Posts 3
Joined 2003-08-31 00:00
22-year member
UID 9239
Gender Male
Status Offline
That's a good method!
Floor 6 Posted 2003-09-13 00:00 ·  中国 安徽 六安 电信
初级用户
Credits 175
Posts 22
Joined 2003-07-24 00:00
23-year member
UID 7466
Gender Male
Status Offline
Many thanks! I originally thought there wouldn't be any good method, but it looks like my understanding of batch files is still far from enough.
Forum Jump: