Windows命令行:不评估环境变量

时间:2022-09-16 00:39:21

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:

我需要这个从命令行配置BizTalk,例如:

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

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.

此命令将资源添加到BizTalk应用程序。我希望目标是%BTAD_InstallDir%\ App1.Schemas.dll,但是目前它正在评估环境变量(没有任何东西)和使用\ 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?

[编辑]当我在命令提示符下执行此操作时,它不会替换环境变量,但是当我将其作为脚本运行时,它是否有任何想法为什么这是不同的?

4 个解决方案

#1


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.

这应该会阻止脚本解释变量,它会将%BTAD_InstallDir%传递给程序。

#2


4  

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

在它打印的命令提示符中尝试echo ^%path ^%...

path

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

而不是扩展环境变量所以我猜以下应该按照Mikeage的建议为你工作

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

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

#3


2  

Try ^% instead of %.

尝试^%而不是%。

#4


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...

[编辑]的确,C:\ PrgCmdLine \ Unix \ echo.exe ^%JAVA_HOME ^%也有效,而且更简单......

[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.

[编辑2]对于记录:我使用UnxUtils的echo来获得普通程序的行为。内置回声具有略微不同的行为,至少对于引用的%符号。

#1


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.

这应该会阻止脚本解释变量,它会将%BTAD_InstallDir%传递给程序。

#2


4  

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

在它打印的命令提示符中尝试echo ^%path ^%...

path

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

而不是扩展环境变量所以我猜以下应该按照Mikeage的建议为你工作

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

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

#3


2  

Try ^% instead of %.

尝试^%而不是%。

#4


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...

[编辑]的确,C:\ PrgCmdLine \ Unix \ echo.exe ^%JAVA_HOME ^%也有效,而且更简单......

[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.

[编辑2]对于记录:我使用UnxUtils的echo来获得普通程序的行为。内置回声具有略微不同的行为,至少对于引用的%符号。