views:

1195

answers:

4

I would like to provide the raw text referring to an environment variable to a command instead of evaluating the environment variable.

I need this to configure BizTalk from the command line, for example:

BTSTask.exe AddResource -ApplicationName:App1 -Type:System.BizTalk:BizTalkAssembly -Overwrite -Source:..\Schemas\bin\development\App1.Schemas.dll -Destination:%BTAD_InstallDir%\App1.Schemas.dll

This command adds a resource to a BizTalk application. I want the destination to be %BTAD_InstallDir%\App1.Schemas.dll, however at present it is evaluating the environment variable (to nothing) and using \App1.Schemas.dll.

Is it possible to escape or disable the evaluation of this environment variable while parsing\executing this command?

I have tried escaping the first and both percentage characters with a carrot (^), however this did not stop the evaluation.

[EDIT] When I execute this at the command prompt it doesn't replace the environment variable, however it does when I run it as a script, any thoughts as to why this is different?

+1  A: 

Try ^% instead of %.

Mikeage
Thanks for your answer Mikeage, unfortunately this still evaluates the environment variable. Maybe I should edit my question to mention approaches I've already tried.
marcj
+1  A: 

Try echo ^%path^% in a command prompt it prints...

path

instead of expanding the environment variable so I guess the following should work for you as suggested by Mikeage

BTSTask.exe AddResource -ApplicationName:App1 -Type:System.BizTalk:BizTalkAssembly -Overwrite -Source:..\Schemas\bin\development\App1.Schemas.dll -Destination:^%BTAD_InstallDir^%\App1.Schemas.dll

SDX2000
Rather bizarrely, even if I don't escape the percentages, this works when I type it directly at the command line, but not when I run it from a .cmd script. Any thoughts?
marcj
+1  A: 

Tried:

C:\PrgCmdLine\Unix\echo.exe "%"JAVA_HOME"%"

Got:

%JAVA_HOME%

[EDIT] Indeed, C:\PrgCmdLine\Unix\echo.exe ^%JAVA_HOME^% works too, and is simpler...

[EDIT 2] For the record: I used UnxUtils' echo to have the behavior of a plain program. Built in echo has a slightly different behavior, at least for quoted % signs.

PhiLho
+2  A: 

Did you try:

%%BTAD_InstallDir%%

in your script ?

That should prevent the script to interpret the variable, and it would pass %BTAD_InstallDir% to the program.

VonC
Fantastic, this works great. Does this work because it can't resolve %BTAD_InstallDir% as a variable and so leaves it as its original value?
marcj
%% is the batch way to not interpret %. Used for variable (as in '%%a instead of %a'), since in batch %1, %2, %3 have special meaning.
VonC