Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 检查结果是否包含在命令应答中_Batch File - Fatal编程技术网

Batch file 检查结果是否包含在命令应答中

Batch file 检查结果是否包含在命令应答中,batch-file,Batch File,仅当命令答案不包括:X-UA-Compatible时,我才尝试运行命令 所以我试过这个: set APPCMD_EXEC=c:\Windows\System32\inetsrv\appcmd.exe for /f "delims=" %%a in ('%APPCMD_EXEC% list config "Default Web site" /section:httpProtocol /text:*') do @set VALUE_1=%%a IF %VALUE_1% EQU [] Echo

仅当命令答案不包括:X-UA-Compatible时,我才尝试运行命令

所以我试过这个:

set APPCMD_EXEC=c:\Windows\System32\inetsrv\appcmd.exe

for /f "delims=" %%a in ('%APPCMD_EXEC% list config "Default Web site" /section:httpProtocol /text:*') do @set VALUE_1=%%a

IF %VALUE_1% EQU [] Echo List Empty
IF %VALUE_1% NEQ [] Echo %VALUE_1%


REM %APPCMD_EXEC% set config "Default Web site" /section:system.webserver/httpProtocol /+"customHeaders.[name='X-UA-Compatible',value='IE=EmulateIE9']"
我得到的答案是

[redirectHeaders]
但如果我只运行命令,我会得到所有这些:

CONFIG
 CONFIG.SECTION:"system.webServer/h
 path:"MACHINE/WEBROOT/APPHOST/Defa
 overrideMode:"Inherit"
 locked:"false"
[system.webServer/httpProtocol]
allowKeepAlive:"true"
[customHeaders]
  [add]
    name:"X-UA-Compatible"
    value:"IE=EmulateIE9"
[redirectHeaders]
那么,我如何才能做到这一点,以便在我的命令应答中找到X-UA-Compatible是否存在?

尝试如下:

@echo off

c:\Windows\System32\inetsrv\appcmd.exe list config "Default Web site" /section:httpProtocol /text:* | find "X-UA-Compatible" && goto:found || echo not found
exit /b

:found
echo Here the command to execute

只有在未找到术语
X-UA-Compatible
时,才会设置
value_1
。for循环中的
find
过滤器在那里有帮助

set APPCMD_EXEC=c:\Windows\System32\inetsrv\appcmd.exe

set "value_1="
for /f "delims=" %%a in ('%APPCMD_EXEC% list config "Default Web site" /section:httpProtocol /text:* ^| find /v "X-UA-Compatible" ') do @set "VALUE_1=%%a"

if not defined VALUE_1 Echo List Empty
if defined VALUE_1 Echo %VALUE_1%


REM %APPCMD_EXEC% set config "Default Web site" /section:system.webserver/httpProtocol /+"customHeaders.[name='X-UA-Compatible',value='IE=EmulateIE9']"
因此,只有在未找到术语的情况下,才能执行示例中的命令:

set APPCMD_EXEC=c:\Windows\System32\inetsrv\appcmd.exe

for /f "delims=" %%a in ('%APPCMD_EXEC% list config "Default Web site" /section:httpProtocol /text:* ^| find /v "X-UA-Compatible" ') do %APPCMD_EXEC% set config "Default Web site" /section:system.webserver/httpProtocol /+"customHeaders.[name='X-UA-Compatible',value='IE=EmulateIE9']"