Chr*_*911 2 windows escaping batch-file
如何在变量中转义引号以与另一个变量进行比较.
示例:脚本输出"test.exe"的输出"正常"(没有周围的引号)
在批处理脚本中,我将输出保存在我的批处理脚本中的变量中,然后想要与保存的变量进行比较.
set ouputTest1 = "The output of "test.exe" is OK"
test.exe -p 75 > temp.txt
set /p TESTOUTPUT=< temp.txt
if %TESTOUTPUT% == %ouputTest1%
Run Code Online (Sandbox Code Playgroud)
问题在于outputTest1变量和字符串中的引号.我尝试使用这样的双引号:
set ouputTest1 = "The output of ""test.exe"" is OK"
Run Code Online (Sandbox Code Playgroud)
但没有运气.
有任何想法吗?
您的代码有三个问题:
脚本行,set ouputTest1 = "The output of "test.exe" is OK"
不创建名为的变量outputTest1
; 相反,它创建一个名为的变量outputTest1<space>
.这就是为什么%outputTest1%
总是空的原因.
在"set"语句中,等号后面的所有内容都被赋值 - 包括空格和外部引号.在你的情况下,变量的内容结束了<space>"The output of "test.exe" is OK"
.
最后,您需要更改IF比较.正确的方法如下:
set "ouputTest1=The output of "test.exe" is OK"
test.exe -p 75 > temp.txt
set /p TESTOUTPUT=< temp.txt
if "%TESTOUTPUT%" == "%ouputTest1%" echo Equal
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3608 次 |
最近记录: |