简体   繁体   中英

Windows Command Line: Non Evaluation of Environment Variable

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.

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? 当我在命令提示符下执行它时,它不会替换环境变量,但是当我将它作为脚本运行时会替换,关于为什么会有所不同的任何想法?

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

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.

尝试 ^% 而不是 %。

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.

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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM