MrDeeJayy
MrDeeJayy

Reputation: 47

How to use the output of a BAT file as a variable in it's parent

( Different from Batch file include external file for variables )

What I'm trying to do is read a batch file, from another batch file. The parent batch file calls upon the child batch file to retrieve a variable from an INI file (the childs sole purpose). It then echos the returned value, and exits. What I want is for the parent batch to pick up this output and use it as a variable for its own operations.

So to clarify: I'm not setting a value in the child process, and would prefer if I didn't have to, because this child process is called twice, to do the same operation twice, but to retrieve different values.

Upvotes: 0

Views: 316

Answers (1)

Stephan
Stephan

Reputation: 56189

the usual way to get a command's output is a forconstruct:

b.bat

@echo hello

a.bat:

for /f %%i in ('b.bat') do set output=%%i
echo %output%

Upvotes: 1

Related Questions