中国DOS联盟论坛

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-02 22:50
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Problems with the CALL statement???
Printable Version  2,357 / 17
Floor1 sunyao Posted 2006-12-01 03:02
初级用户 Posts 60 Credits 141 From 天津
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.
Floor2 pkone Posted 2006-12-01 03:33
初级用户 Posts 8 Credits 25
Determine based on the abnormal return value in a.bat:
if level XXX=xxx exit
Floor3 sunyao Posted 2006-12-01 04:00
初级用户 Posts 60 Credits 141 From 天津
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
Floor4 KIKOOOO Posted 2006-12-01 04:34
初级用户 Posts 12 Credits 34
根据用户提供的内容,直接翻译的话是:

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
Floor5 sunyao Posted 2006-12-01 05:28
初级用户 Posts 60 Credits 141 From 天津
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.
Floor6 zh159 Posted 2006-12-01 06:23
金牌会员 Posts 1,467 Credits 3,687
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
Floor7 sunyao Posted 2006-12-01 06:33
初级用户 Posts 60 Credits 141 From 天津
Actually, strictly speaking, it's not an exception. It's a branch of the program. If the branch is executed, it ends all programs.
Floor8 lxmxn Posted 2006-12-01 07:17
版主 Posts 4,938 Credits 11,386

Try adding the following statement to b.bat:

Floor9 sunyao Posted 2006-12-01 07:20
初级用户 Posts 60 Credits 141 From 天津
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
Floor10 lxmxn Posted 2006-12-01 07:27
版主 Posts 4,938 Credits 11,386

  Have you tried it?

          Facts speak louder than words!
Floor11 sunyao Posted 2006-12-01 07:36
初级用户 Posts 60 Credits 141 From 天津
Really not working. I'm sorry.
Floor12 lxmxn Posted 2006-12-01 07:40
版主 Posts 4,938 Credits 11,386

  Why doesn't it work? Please tell me the purpose you want to achieve and the running result.
Floor13 sunyao Posted 2006-12-01 07:47
初级用户 Posts 60 Credits 141 From 天津
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.
Floor14 lxmxn Posted 2006-12-01 08:00
版主 Posts 4,938 Credits 11,386
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?
Floor15 redtek Posted 2006-12-01 12:34
金牌会员 Posts 1,147 Credits 2,902
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


2.bat
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023