|
sunyao
初级用户
 
积分 141
发帖 60
注册 2006-10-28 来自 天津
状态 离线
|
『楼 主』:
call语句的问题???
使用 LLM 解释/回答一下
有两个bat文件:a.bat和b.bat
在b.bat中call a.bat
现在想在call a.bat时如果a.bat发生异常就不再返回b.bat了
不知道怎么实现
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.
|
|
2006-12-1 03:02 |
|
|
pkone
初级用户
 
积分 25
发帖 8
注册 2006-11-27
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
根据a.bat里的异常返回值判断
if level XXX=xxx exit
Determine based on the abnormal return value in a.bat:
if level XXX=xxx exit
|
|
2006-12-1 03:33 |
|
|
sunyao
初级用户
 
积分 141
发帖 60
注册 2006-10-28 来自 天津
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
判断可以做到
exit只能终止a.bat
可还是要返回到b.bat中继续执行b.bat
我的意思是如果a.bat异常就不再返回b.bat
整个程序终止也就是一旦a.bat异常就什么都不执行了
别忘了整个程序是执行b.bat 在b.bat中call a.bat
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
|
|
2006-12-1 04:00 |
|
|
KIKOOOO
初级用户
 
积分 34
发帖 12
注册 2006-9-25
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
根据返回值来终止a.bat
goto :eof
根据用户提供的内容,直接翻译的话是:
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
|
|
2006-12-1 04:34 |
|
|
sunyao
初级用户
 
积分 141
发帖 60
注册 2006-10-28 来自 天津
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
还是没看懂我的问题
我在a.bat异常时不仅要结束a.bat还要结束b.bat
b.bat也不执行了
goto:eof
只会结束a.bat 但还要返回b.bat继续执行剩下的程序
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.
|
|
2006-12-1 05:28 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
LZ没明白 2 楼 pkone 的意思:
a.bat里发生异常,一般会有一个异常返回值,b.bat里用if level XXX=xxx exit判断该异常返回值结束运行
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
|
|
2006-12-1 06:23 |
|
|
sunyao
初级用户
 
积分 141
发帖 60
注册 2006-10-28 来自 天津
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
其实严格讲并不是一个异常
是程序的一个分支
如果执行分支就结束所有程序
Actually, strictly speaking, it's not an exception. It's a branch of the program. If the branch is executed, it ends all programs.
|
|
2006-12-1 06:33 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
b.bat中加入下面的一个语句试试:
call a.bat || goto :eof
Try adding the following statement to b.bat:
call a.bat || goto :eof
|
|
2006-12-1 07:17 |
|
|
sunyao
初级用户
 
积分 141
发帖 60
注册 2006-10-28 来自 天津
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
这样好像不行吧
call a.bat || goto :eof
这句好像是call a.bat 失败才执行goto :eof
但事实上并不是call a.bat 失败
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
|
|
2006-12-1 07:20 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
你试过了没有?
事实胜于雄辩!
Have you tried it?
Facts speak louder than words!
|
|
2006-12-1 07:27 |
|
|
sunyao
初级用户
 
积分 141
发帖 60
注册 2006-10-28 来自 天津
状态 离线
|
|
2006-12-1 07:36 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
怎么不行?把你要实现的目的和运行结果说一下。
Why doesn't it work? Please tell me the purpose you want to achieve and the running result.
|
|
2006-12-1 07:40 |
|
|
sunyao
初级用户
 
积分 141
发帖 60
注册 2006-10-28 来自 天津
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
b.bat中call a.bat
我在a.bat脚本中做一个判断
如果状态为fail,就向log中输出“异常”
同时结束a.bat和b.bat
现在是a.bat结束但b.bat还要执行到程序结束
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.
|
|
2006-12-1 07:47 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
实在听不懂你说的什么意思,两个bat能完成的,一个bat就可以完成,可以合并起来。p.s.:log 是指的什么东西啊?
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?
|
|
2006-12-1 08:00 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
我也看得不太明白,这是一个 1.bat Call 2.bat 的是否正常运行了 2.bat 的测试代码:)
你可以将 2.bat 改名试试(故意制造一个错误),这个时候,1.bat就会知道2.bat运行的时候出错了,并输出相关信息……
sunyao兄可以参考原理……
运行环境: Windows CMD Shell
1.bat
@echo off
Call 2.Bat 02
:: 判断所 Call 之 2.Bat 是否运行成功,只要有预设errorlevel返回值,就是运行成功!
if %errorlevel%==1000 ( echo 2.Bat 成功执行! ) else ( echo 2.Bat 运行失败! )
2.bat
@echo off
if == exit /b
goto :%1
:01
echo 01 标签段
goto :end
:02
echo 02 标签段
goto :end
:end
exit /b 1000
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,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-12-1 12:34 |
|