简体   繁体   English

批处理文件:返回给调用者?

[英]Batch File: Return to caller?

What is the equivalent of the return statement for a batch file subroutine?批处理文件子例程的return语句等效于什么?

It is:这是:

goto :eof

This is understandably unusual for somebody accustomed to normal programming languages.对于习惯于普通编程语言的人来说,这是可以理解的不寻常的。

I found this info here .我在这里找到了这个信息。

I think that it is:我认为是:

exit /b [exitCode]

Not just because it is more understandeable to use, but also because exit /b (and just exit also) may return an exitCode (ERRORLEVEL) value to the caller program.不仅因为它更易于使用,还因为 exit /b(也只是 exit)可能会向调用程序返回一个 exitCode (ERRORLEVEL) 值。

In my modest opinion, goto:eof is a strange patch that should not be used...在我看来,goto:eof 是一个不应该使用的奇怪补丁......

Goto :Eof

Exit

Goto:Eof usually use in call command such as: Goto:Eof 通常在调用命令中使用,例如:

@echo off
call :Hi
pause&exit
:hi
echo Hello!
goto :eof 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM