I need to assign the output of a program to a variable using a MS batch file.
So in GNU Bash shell I would use VAR=$(application arg0 arg1)
. I need a similar behavior in Windows using a batch file.
Something like set VAR=application arg0 arg1
.
batch-filecmdvariable-assignmentwindows-console
I need to assign the output of a program to a variable using a MS batch file.
So in GNU Bash shell I would use VAR=$(application arg0 arg1)
. I need a similar behavior in Windows using a batch file.
Something like set VAR=application arg0 arg1
.
Best Answer
One way is:
Another is:
Note that the first
%
in%%i
is used to escape the%
after it and is needed when using the above code in a batch file rather than on the command line. Imagine, yourtest.bat
has something like: