I have a batch variable, which contains the name of another variable. When I perform a CALL ECHO
on the variable, the output is what I expect. However, when I try to pipe the output of the CALL ECHO
command as an argument to another command, I am running into issues. This is what I am attempting:
@SET myCmd=myCmd -flag1 -flag2
@SET myInnerVar=Bar
@SET myCmdArg="Value of myInnerVar is %%myInnerVar%% for this call"
:: The following correctly prints "Value of myInnerVar is Bar for this call"
@CALL ECHO %myCmdArg%
:: The following runs without passing the output as an argument to myCmd
@CALL ECHO %myCmdArg%| %myCmd%
Does anyone know how to call myCmd using delayed variable expansion, as if it was called directly with the arguments:
@myCmd -flag1 -flag2 "Value of myInnerVar is Bar for this call"
The reason I am trying to do this is that I need to call myCmd multiple times, where the only thing that is changing is the string "Bar". I know that I could do this using three variables (myCmdPre, myInnerVar, and myCmdPost) without delayed variable expansion. However, it seems like there should be another (more concise) way to accomplish my goal without having to type %myCmdPre%%myInnerVar%%myCmdPost%
every time I want to execute myCmd.
EDIT
To clarify, I wrote a second batch file in the same directory called myCmd.bat, with the following content:
@ECHO %*
When I run my example batch file, the output that is generated is:
-flag1 -flag2
It is as if nothing is being piped to myCmd.