简体   繁体   English

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

[英]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:我需要这个来从命令行配置 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.此命令将资源添加到 BizTalk 应用程序。 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.我希望目标是 %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? [编辑]当我在命令提示符下执行它时,它不会替换环境变量,但是当我将它作为脚本运行时会替换,关于为什么会有所不同的任何想法?

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

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%传递给程序。

尝试 ^% 而不是 %。

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. [编辑 2] 作为记录:我使用 UnxUtils 的 echo 来获得普通程序的行为。 Built in echo has a slightly different behavior, at least for quoted % signs.内置 echo 的行为略有不同,至少对于引用的 % 符号。

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.不确定它是否与我的情况相同,但我很难使用批处理文件来创建一个内部包含 %temp% 变量的脚本。 The workaround i found: set test=%temp;我发现的解决方法: set test=%temp; echo {command} %test%%>>path_to_my_batch_file;回声 {命令} %test%%>>path_to_my_batch_file; Hope this helps someone:)希望这可以帮助某人:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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