Can't set return value in batch file

Lefix

I'm trying to get a batch file containing a simple function that get parameter/s and return values. Actually i'm not able to do this!

test.bat:

@echo off
setlocal EnableDelayedExpansion

set arg=bar
echo my args %*
echo my new value %arg%

endlocal&set %~1=%arg%

main.bat:

@echo off
setlocal EnableDelayedExpansion

set var1=foo
echo Old value: %var1%
call test.bat %var1%
echo New value: %var1%

This is what the console return:

Old value: foo
my args: foo
my new value: bar
New value: foo
Compo

In main.bat you need to echo the value content of %foo% not the value content of %var1%:

Change:

echo New value: %var1%

To:

Echo New value: !%var1%!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can't set the value of a file input with javascript

How can I use return data set a new parameters in batch file?

Windows batch file return code isn't set if there's a following line

In Jenkins Groovy script, how can I grab a return value from a batch file

Batch file - set parameter value and then pass to exe

Export registry value to file and then set a variable in Batch

Batch Can't Set inside IF Block

Can't return the assigned value

Can't return value in Golang

How to set random value from a set of strings in Batch file?

Can't run batch file in Server 2012

Can't stop VBScript in batch file

I want to write a batch file that internally calls python script and I want python script to return some value to the batch file. how can I do that?

Set value and clear value in batch while reading from file in windows

Can't set a value on a cell

Can't set property value

Reading Value from Text file to set in batch file variable

SimpleJdbcCall for MySql Function yields "Can't set IN parameter for return value of stored function call"

Mongoose query inside a forEach loop can't return or set value for sum variable

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

Get Return Value from Console Application in Batch file

Using set in a batch cmd file to update a variable value

How to set a variable value based on if-statement in batch file

Using jQuery read a txt file can't return the value out of the function

Can't open a .chm file from a batch file

"Can't read file" when trying to Exclude directory in batch file

How can I set a time-limit on a batch file?

How can multiple dependent variables be set on the same line in a batch file?

How can I set a WMIC Variable in a batch file?