5

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?

marcj
  • 914
  • 1
  • 7
  • 10

5 Answers5

4

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

Sandeep Datta
  • 28,607
  • 15
  • 70
  • 90
  • 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 Nov 27 '08 at 11:16
3

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
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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 Nov 27 '08 at 13:00
  • 1
    %% 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 Nov 27 '08 at 13:02
2

Try ^% instead of %.

Mikeage
  • 6,424
  • 4
  • 36
  • 54
  • 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 Nov 27 '08 at 10:45
1

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
  • 40,535
  • 6
  • 96
  • 134
0

Not sure if it's the same as my case, but i was troubling to use a batch file to create a script which has %temp% variable inside. The workaround i found: set test=%temp; echo {command} %test%%>>path_to_my_batch_file; Hope this helps someone:)