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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6728691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:35:33  来源:igfitidea点击:

Batch File: Return to caller?

windowsbatch-filereturn-valuereturn

提问by user541686

What is the equivalent of the returnstatement for a batch file subroutine?

return批处理文件子程序的语句等效于什么?

采纳答案by Greg Hewgill

It is:

这是:

goto :eof

This is understandably unusual for somebody accustomed to normal programming languages.

对于习惯于普通编程语言的人来说,这是可以理解的不寻常。

I found this info here.

我在这里找到了这个信息。

回答by Aacini

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 (也只是退出)可能会向调用程序返回 exitCode (ERRORLEVEL) 值。

In my modest opinion, goto :eof is a strange patch that should not be used...

在我看来, goto :eof 是一个不应该使用的奇怪补丁......

回答by GaryNg

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