Link to home
Start Free TrialLog in
Avatar of deepak singla
deepak singla

asked on

Return result to caller batch file

I have two batch files A.bat and B.bat. A.bat is calling to B.bat.
B.bat is doing some processing, and return back the result to A.bat. How A.bat can accept the return?

@echo off
set str1=1,2,3,4,5
set str2=6,7,8,9
call B.bat %str1% %str2%

@echo off
set str1=%1
set str2=%2
set str3=%str1%,%str2%

Expected that B.bat return %str3% (means 1,2,3,4,5,6,7,8,9) back to A.bat file So that A.bat used the result for further processing.
Avatar of oBdA

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oBdA write it already: there is no function in a command shell batch. You can only call/jump to methods. But you can set global variables.

In the case of different batch files: The process is called piping. Thus the use of Echo to output the result to the standard pipe is the correct approach.

So I would thus use a slightly different syntax for the "function" result in a closed batch, call it a different flavor:

@Echo Off

Set Str1=1,2,3,4,5
Set Str2=6,7,8,9
Call :JoinStrings "%Str1%" "%Str2%"
Echo Result: %_Result%

GoTo :Eof

:JoinStrings  <String 1> <String 2>

Set Str1=%~1
Set str2=%~2
Set Result=%Str1%,%Str2%

EndLocal & Set _Result=%Result%
GoTo :Eof

Open in new window