[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理中变量延迟及管道符怎么使用?

见图或下面拷屏,涉及变量延缓及管道的问题,实在想不明白,请高手指点,谢谢。
===============================
C:\>more b.bat
@Echo Off & Setlocal Enabledelayedexpansion & setlocal EnableExtensions
set a=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\11
set b=    ServiceName REG_SZ  {4A966A11-AE30-4187-B6D1-7C029202087D}
set c=    Description REG_SZ  Realtek RTL8139/810x Family Fast Ethernet NIC
@echo !a! ^| findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
@echo !b! ^| findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
@echo !c! ^| findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO

C:\>b.bat
YES
YES
YES

C:\>@echo HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\11 | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul && echo YES || echo NO
NO

C:\>@echo     ServiceName REG_SZ  {4A966A11-AE30-4187-B6D1-7C029202087D} | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul && echo YES || echo NO
NO

C:\>@echo     Description REG_SZ  Realtek RTL8139/810x Family Fast Ethernet NIC | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul && echo YES || echo NO
YES
1

评分人数

    • pcl_test: 优先文字说明,能用文字说明清楚的勿发图片PB -2

建议LZ先把基础学好
  1. @echo off
  2. set "a=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\11"
  3. set "b=    ServiceName REG_SZ  {4A966A11-AE30-4187-B6D1-7C029202087D}"
  4. set "c=    Description REG_SZ  Realtek RTL8139/810x Family Fast Ethernet NIC"
  5. echo,%a%|find "Realtek RTL8139/810x Family Fast Ethernet NIC">nul&&echo YES||echo NO
  6. echo,%b%|find "Realtek RTL8139/810x Family Fast Ethernet NIC">nul&&echo YES||echo NO
  7. echo,%c%|find "Realtek RTL8139/810x Family Fast Ethernet NIC">nul&&echo YES||echo NO
  8. pause
复制代码

TOP

回复 2# pcl_test
该脚本仅仅实际脚本抽出来测试错误的一部分,实际脚本用有使用for及需启用环境变量延缓,而不仅仅是预处理的变量替换。在启用环境变量延缓的情况下应该如何处理?谢谢。

TOP

已解决,见下
=============================
C:\>more b.bat
@Echo Off & Setlocal Enabledelayedexpansion & setlocal EnableExtensions
set a=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\11
set b=    ServiceName REG_SZ  {4A966A11-AE30-4187-B6D1-7C029202087D}
set c=    Description REG_SZ  Realtek RTL8139/810x Family Fast Ethernet NIC
echo !a! | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
echo !b! | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
echo !c! | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
echo.
echo !a! ^| findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
echo !b! ^| findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
echo !c! ^| findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
echo.
endlocal Enabledelayedexpansion & endlocal EnableExtensions
echo %a% | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
echo %b% | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO
echo %c% | findstr /C:"Realtek RTL8139/810x Family Fast Ethernet NIC" >nul  && echo YES || echo NO

C:\>b.bat
NO
NO
YES

YES
YES
YES

NO
NO
YES

C:\>

TOP

返回列表