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-02 21:41
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Problems with the CALL statement??? View 2,355 Replies 17
Original Poster Posted 2006-12-01 03:02 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
There are two batch files: a.bat and b.bat. In b.bat, call a.bat. Now I want that if an exception occurs in a.bat when calling a.bat, it won't return to b.bat. I don't know how to implement this.
Floor 2 Posted 2006-12-01 03:33 ·  中国 湖北 鄂州 电信
初级用户
Credits 25
Posts 8
Joined 2006-11-27 03:22
19-year member
UID 71845
Gender Male
Status Offline
Determine based on the abnormal return value in a.bat:
if level XXX=xxx exit
Floor 3 Posted 2006-12-01 04:00 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
It can be done.
exit can only terminate a.bat, but it still needs to return to b.bat to continue executing b.bat. What I mean is if a.bat has an exception, it will no longer return to b.bat. The whole program terminates, that is, once a.bat has an exception, nothing is executed. Don't forget that the whole program executes b.bat, and in b.bat, call a.bat
Floor 4 Posted 2006-12-01 04:34 ·  中国 浙江 杭州 电信
初级用户
Credits 34
Posts 12
Joined 2006-09-25 04:45
19-year member
UID 63588
Gender Male
Status Offline
根据用户提供的内容,直接翻译的话是:

Terminate a.bat according to the return value

goto :eof

不过需要注意原句中“根据返回值来终止a.bat”翻译为“Terminate a.bat according to the return value”,“goto :eof”保持原样。所以整体翻译后就是:

Terminate a.bat according to the return value
goto :eof
Floor 5 Posted 2006-12-01 05:28 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Still don't understand my question. When a.bat is abnormal, I need not only to end a.bat but also to end b.bat. b.bat also doesn't execute anymore. goto:eof will only end a.bat, but I still need to return to b.bat to continue executing the remaining program.
Floor 6 Posted 2006-12-01 06:23 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
LZ didn't understand the meaning of user pkone on the 2nd floor:

There is usually an exception return value when an exception occurs in a.bat. In b.bat, use if level XXX=xxx exit to judge the exception return value and end the operation
Floor 7 Posted 2006-12-01 06:33 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Actually, strictly speaking, it's not an exception. It's a branch of the program. If the branch is executed, it ends all programs.
Floor 8 Posted 2006-12-01 07:17 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

Try adding the following statement to b.bat:

call a.bat || goto :eof

Floor 9 Posted 2006-12-01 07:20 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
This doesn't seem to work, right?
call a.bat || goto :eof
This sentence seems to mean that if call a.bat fails, then execute goto :eof
But in fact, it's not that call a.bat fails
Floor 10 Posted 2006-12-01 07:27 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  Have you tried it?

          Facts speak louder than words!
Floor 11 Posted 2006-12-01 07:36 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Really not working. I'm sorry.
Floor 12 Posted 2006-12-01 07:40 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  Why doesn't it work? Please tell me the purpose you want to achieve and the running result.
Floor 13 Posted 2006-12-01 07:47 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
In b.bat, there is "call a.bat". I make a judgment in the a.bat script. If the status is "fail", output "Abnormal" to the log. At the same time, end both a.bat and b.bat. Now, a.bat ends but b.bat still has to execute until the program finishes.
Floor 14 Posted 2006-12-01 08:00 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
I really don't understand what you mean. What can be done with two bats can be done with one bat, and they can be combined. P.S.: What does "log" refer to?
Floor 15 Posted 2006-12-01 12:34 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
I also don't understand it very well. This is a test code for whether 1.bat Call 2.bat runs normally : )

You can try renaming 2.bat (deliberately creating an error). At this time, 1.bat will know that an error occurred when 2.bat was running and output relevant information...

Brother sunyao can refer to the principle...



Running environment: Windows CMD Shell

1.bat

@echo off

Call 2.Bat 02

:: Judge whether the called 2.Bat runs successfully. As long as there is a preset errorlevel return value, it runs successfully!
if %errorlevel%==1000 ( echo 2.Bat executed successfully! ) else ( echo 2.Bat failed to run! )


2.bat

@echo off

if == exit /b
goto :%1

:01
echo 01 label segment
goto :end

:02
echo 02 label segment
goto :end

:end
exit /b 1000
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Forum Jump: