batch file: Setting a variable to the return value from a function call

Aenaon

What I am doing wrong here please? I want to make a windows batch file that will call an exe, passing in some arguments and assign the return value to a variable. I have tried lots of different variations of the following but I cant make it work.

SET EXE="path\to\exe"
SET TARGET_FILE="path\to\file\to\be\read\by\exe"

for /f %%i in (%EXE% -arg1 %TARGET_FILE%) do set VAR=%%i

ECHO %VAR%
PAUSE

What am I missing? In case it matters, the two paths above will probably contain spaces, line C:\Program Files\etc.

RobertBaron

The following batch file should work. I have not tested, let me know if it does not.

SET EXE="path\to\exe"
SET TARGET_FILE="path\to\file\to\be\read\by\exe"

for /f "delims=" %%i in ('"%EXE% -arg1 %TARGET_FILE%"') do (
echo %%i
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how I can call from batch file a java script function with 2 arguments and return the result to a dos variable

Setting Lines From A File to a Variable in Batch Script

JavaScript setting value to variable properties on a function call

Setting up variable to return function value or false

Batch File not setting variable

Setting variable to a return from a callback function

How to call VBA function from batch file

Setting a value of class variable from another function

Setting a variable's value directly from a function

Get variable value from for loop in batch file

Setting a system environment variable from a Windows batch file?

Batch Reading from different file, and setting each two characters as a variable

How to return custom value from function call?

Return the same value from a second function call

function that return a value from ajax call request

Return Flutter Value from function call

angularjs call function from html return value

php function return from db and call the value from separated view file

Batch file value in variable

Return a value coming directly from a function call vs. an intermediate variable

Return value of a function changes the original variable used to call the function automatically

SQUIRREL: assigning return value from a function to a variable

Call PHP function variable from separate file

Setting a variable equal to a return of function

Call .exe from batch file with variable path containing spaces

Return variable from stored procedure call as output value for variable

setting a variable from a file

Reading Value from Text file to set in batch file variable

How to call a specific Python function from a batch file?