Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch File: Return to caller?

What is the equivalent of the return statement for a batch file subroutine?

like image 898
user541686 Avatar asked Jul 18 '11 04:07

user541686


People also ask

How do you return a value from a batch file?

Syntax. It is common to use the command EXIT /B %ERRORLEVEL% at the end of the batch file to return the error codes from the batch file. EXIT /B at the end of the batch file will stop execution of a batch file. Use EXIT /B < exitcodes > at the end of the batch file to return custom return codes.

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

What does %% do in batch?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

What is %% g'in batch file?

%%parameter : A replaceable parameter: in a batch file use %%G (on the command line %G) FOR /F processing of a command consists of reading the output from the command one line at a time and then breaking the line up into individual items of data or 'tokens'.


2 Answers

It is:

goto :eof 

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

I found this info here.

like image 163
Greg Hewgill Avatar answered Oct 14 '22 15:10

Greg Hewgill


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.

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

like image 29
Aacini Avatar answered Oct 14 '22 13:10

Aacini