windows - 在 Windows 批处理文件中静音 For 的命令输出
问题描述
如果存在 SRV 记录,则以下代码片段完全符合我的要求,即打印出带有 SRV 记录的每个服务器。但是,如果未找到 SRV 记录(在某些情况下这是预期的,我会看到错误。
:: Execute a Nslookup for the internal SRV Record and collect the FQDNs of the response
:TESTPUBLICDNS
for /f "usebackq tokens=1,2 delims=" %%f in (`c:\Windows\System32\nslookup.exe -q^=srv %publicSRV%%domain% ^| findstr /R /C:"hostname"`) do (
set "hostFQDNFull=%%f"
:: Split the result to extract just the FQDN of the servers in the SRV Record
for /f "usebackq tokens=1,2 delims==" %%a in (`echo !hostFQDNFull!`) do set label=%%a&set hostFQDN=%%b
set hostFQDN=!hostFQDN: =!
echo !hostFQDN!
)
因此,如果存在 SRV 记录,我将得到:
server1.wdgets.com
server2.wdgets.com
server3.wdgets.com
但如果不是,我得到:
*** dnsserver.local can't find _sanitizedsrv._tcp.widgets.com: Non-existent domain
当结果是这样时,我想使“不存在”的域输出静音。我似乎无法弄清楚如何做到这一点。如果我将 For 循环重定向到 Null,我会丢失 Do 部分中的结果。
解决方案
推荐阅读
- reactjs - 为什么这不适用于 recompose 和 ramda?
- html - 如何缩放高度数字微调器(输入类型 =“数字”)
- android - SQLite插入具有相同值的多行
- sql-server - 如何获得 H12_LC、F12_LC、Sales_LC 列的总和?
- dialogflow-es - Dialogflow 提供对意图有效的特定选项
- aurelia - IdentityServer 的 Aurelia 和 Open-Id-Connect 插件
- jquery - 获取 div 容器中的最大值
- c++ - 通过指针调用模板类成员函数[为什么这是有效的 c++]?
- c - 未定义对“powerOfThree”的引用
- javascript - 全屏 jQuery 中的 ScrollTop