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-03 20:34
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to skip unresponsive programs && question about parallel processing View 946 Replies 11
Original Poster Posted 2007-03-25 03:14 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Calling an external program from a batch file;

this program may either run successfully or fail;

if it succeeds, it will probably return to the original batch file in about 2 seconds and continue with the next command;

if it fails, it will take more than 10 seconds to return to the original batch file;

since this is executed in a loop, the execution efficiency becomes very low;

I want to know how to forcibly terminate a program that failed to execute, and directly execute the command below;

that is, only allow the program 3 seconds to run;

if it succeeds, then it will definitely succeed within 3 seconds; and the command below will also be executed;

if it fails, then as soon as 3 seconds are up it will forcibly terminate itself and go execute the command below; I don't know whether this can be done;



Can a batch file execute in parallel?


For example

batch file
|
|
program
|
|
program
|
|
program
|
.
.
.


Can it be made to do this

batch file
|
|
--------------------------------------
| | | | | | | | .....
| | | | | | | |
program program program program program program program program




[ Last edited by bjsh on 2007-3-24 at 02:15 PM ]
Floor 2 Posted 2007-03-25 03:18 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
A batch file can only use the "start command" method to open new windows and run multiple commands at the same time; it cannot execute in parallel internally
Floor 3 Posted 2007-03-25 05:06 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
You can try it like this
start command
check process static
check process static
check process static
Each time you start a program, check its status three times. If it is not responding even once, then kill it. If not, then start the next one
Floor 4 Posted 2007-03-25 07:25 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Originally posted by zh159 at 2007-3-24 02:18 PM:
Batch files can only use the "start command" method to open a new window and run multiple commands at the same time; they cannot execute in parallel internally

Mm; yes; I found that out myself too.
Floor 5 Posted 2007-03-25 22:05 ·  中国 广东 广州 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
Originally posted by everest79 at 2007-3-24 16:06:
You can try it like this
start command
check process static
check process static
check process static
After starting each program, check its status three times. If it is non-responsive even once, then kill it; if not, then start the next one.



Isn't check not an internal command? How can you tell that it is not responding? Please advise?
Floor 6 Posted 2007-03-25 22:41 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
...I was just giving an example, there is no such command
Floor 7 Posted 2007-03-25 22:43 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
For example, the following

tasklist /fi "imagename eq %1" /fi "status ne running"&&taskkill /f "imagenmae eq %1"
Floor 8 Posted 2007-03-26 01:00 ·  中国 广东 广州 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
. batch file
|
|
--------------------------------------
| | | | .....
| | | |
a.exe b.exe c.exe

My PS skills are poor, can it be understood as:

start a.exe
tasklist /fi "a.exe eq %1" /fi "status ne running"&&taskkill /f "a.exe eq %1"
start b.exe
tasklist /fi "b.exe eq %1" /fi "status ne running"&&taskkill /f "b.exe eq %1"
......

[ Last edited by axi on 2007-3-25 at 12:03 PM ]
Floor 9 Posted 2007-03-26 01:11 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Something like that
Floor 10 Posted 2007-03-26 01:22 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
This is what I mean

start a.exe&&set exefile=%exefile%;"a.exe"
call :chkeck
start b.exe&&set exefile=%exefile%;"b.exe"
call :chkeck
...

:chkeck
for /f "delims=;" %%i in ("%exefile%") do (
taskkill /f /im %%i /fi "status ne running"
)

[ Last edited by everest79 on 2007-3-25 at 12:24 PM ]
Floor 11 Posted 2007-03-26 01:51 ·  中国 广东 广州 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
Floor 12 Posted 2007-03-26 02:18 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Hehe, I'm getting smarter and smarter
Forum Jump: