![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-13 03:26 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS学习入门 & 精彩文章 (教学室) » How to tell in a batch file whether a program is already running? |
| Printable Version 1,180 / 5 |
| Floor1 daiddcc | Posted 2003-09-02 00:00 |
| 初级用户 Posts 22 Credits 175 | |
|
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? |
|
| Floor2 红色狂想 | Posted 2003-09-03 00:00 |
| 金牌会员 Posts 1,501 Credits 4,289 From 河南省 | |
|
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.
|
|
| Floor3 willsort | Posted 2003-09-06 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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 |
|
| Floor4 cn_archer | Posted 2003-09-06 00:00 |
| 元老会员 Posts 991 Credits 2,903 From 福建省 | |
|
The method from the poster above is very practical!
|
|
| Floor5 congcong | Posted 2003-09-09 00:00 |
| 初级用户 Posts 3 Credits 112 | |
|
That's a good method!
|
|
| Floor6 daiddcc | Posted 2003-09-13 00:00 |
| 初级用户 Posts 22 Credits 175 | |
|
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.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |