中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 10:05
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Problems with delay variables
Printable Version  1,842 / 5
Floor1 jun19841 Posted 2010-12-06 14:46
初级用户 Posts 29 Credits 55 From 亚洲
@echo off&setlocal enabledelayedexpansion
for /f "usebackq tokens=2 delims=:" %%i in (`ipconfig ^| find "Default Gateway"`) do set gw=%%i
for /f "usebackq tokens=2 delims= " %%i in (`arp -a ^| findstr "\<!gw!\>"`) do echo %%i
pause

Why can getting the MAC address of the gateway work when using `findstr "\<10.0.0.1\>"`
but not when using the delayed variable !gw!?

[ Last edited by jun19841 on 2010-12-6 at 14:58 ]
Floor2 Hanyeguxing Posted 2010-12-06 15:12
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
Look at my place http://www.cn-dos.net/forum/viewthread.php?tid=52933&fpage=2
The explanation on floor 11!~
It's because you have already brought the space in when setting gw=%%i
The result is "space + Default Gateway"
The correct way should be written like this:

%gw:~1% is used to remove the leading space that was brought in
Floor3 jun19841 Posted 2010-12-06 15:20
初级用户 Posts 29 Credits 55 From 亚洲
Thanks to Hanyeguxing for the guidance, I've learned it~
Floor4 jun19841 Posted 2010-12-06 15:21
初级用户 Posts 29 Credits 55 From 亚洲
Originally posted by Hanyeguxing at 2010-12-6 15:12:
Check the explanation on floor 11 of http://www.cn-dos.net/forum/viewthread.php?tid=52933&fpage=2!~
You already included the space when you did set gw=%%i
The result is "space + Default Gateway ...



Hmm, inserting call can also be used to call, learned~
Floor5 jun19841 Posted 2010-12-06 15:24
初级用户 Posts 29 Credits 55 From 亚洲
for /f "usebackq tokens=2 delims= " %%i in (`arp -a ^| findstr "\<call !gw!\>"`) do echo %%i
for /f "usebackq tokens=2 delims= " %%i in (`arp -a ^| findstr "\<!gw:~1!\>"`) do echo %%i
Floor6 acaigg Posted 2010-12-25 12:31
初级用户 Posts 92 Credits 115
Learning
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023