Post by Pegasus [MVP]Post by Petr LaznovskyHi there, I am beginner in the CMD scripting.
I want to get interface list, each iface into each variable. I have two
for /f "tokens=3,* delims= " %i in ('netsh in sh in') do echo %i %j
I am use local (Czech) language version of WXP and the tranlation of nesth
use two words for loopback ("zpetna smycka" something like "loop back"
with space between those two words). When I try to parse it, there is
problem with delimiter bacause there are two words for loopback in the
Admin State State Type Interface Name
-------------------------------------------------------------------------
Enabled Dedicated dummy
Enabled Dedicated Local Area Connection
Enabled Internal Internal
Enabled Loop Back Loop Back
Second probles is I have no idea how to push ecach line of output (name of
each iface) into separated variable.
Any ideas??
Petr Laznovsky
When I run the command
for /f "tokens=3,* delims= " %i in ('netsh in sh in') do echo %i %j
then my console output looks radically different from yours,
The output I post is not output from full parsing command, but from
"netsh in sh in" in English OS version. I want to demonstrate the "two
words for loopback" problem. Real outpul from "netsh in sh in" is following:
Admin. stav Stav Typ Název rozhraní
-------------------------------------------------------------------------
Povoleno Vyhrazený Bluetooth Network
Povoleno Vyhrazený ETH0
Povoleno Vyhrazený WLAN0
Povoleno Vyhrazený Bezdrátové pøipojení k síti 4
Povoleno Vyhrazený Bezdrátové pøipojení k síti 2
Povoleno Vyhrazený Hamachi
Povoleno Vyhrazený Bezdrátové pøipojení k síti 3
Povoleno Vnitøní Vnitøní
Povoleno Zpìtná smyèka Zpìtná smyèka
--------------------------------------------------------------------------
Output from real FOR /F command is:
-----------------------------------------------------------
c:\>echo Stav Typ Název rozhraní
Stav Typ Název rozhraní
c:\>echo Bluetooth Network
Bluetooth Network
c:\>echo ETH0
ETH0
c:\>echo WLAN0
WLAN0
c:\>echo Bezdrátové pøipojení k síti 4
Bezdrátové pøipojení k síti 4
c:\>echo Bezdrátové pøipojení k síti 2
Bezdrátové pøipojení k síti 2
c:\>echo Hamachi
Hamachi
c:\>echo Bezdrátové pøipojení k síti 3
Bezdrátové pøipojení k síti 3
c:\>echo Vnitøní
Vnitøní
c:\>echo smyèka Zpìtná smyèka
smyèka Zpìtná smyèka
----------------------------------------------------------
on last line you can see: "back Loop back" instead of "Loop back" or
"Loopback"
even when
Post by Pegasus [MVP]allowing for linguistic differences. I am therefore unable to give you a
solution that is guaranteed to work for you. And while I appreciate that the
Czech translation of "loopback" generates two words, I do not understand
what you're trying to extract from the console output.
I am administrator of IP network consist of many small subnets (/27 and
/29) without use of DHCP. Technicians with the laptops win WXP need time
by time connect to some subnets in some racks and need to change IP
address manually which take some time and mistakes are done frequently.
Therefor I wrote attached batch which allow him to choose location from
batch menu and batch will setup IP subsystem automatically. But there is
one issue: Setup address automatically by netsh need to provide iface
name and because on some node technicians connect through ethernet aand
on some nodes tahy need to connect throuh wireless my idea is first
provide him menu with list of network adapters present in the laptop,
let him choose adapter, than fill adapter name into variable and pass
into next part of batch (already done) which is choose
location/ip_address and setup to system.
Sorry for my poor english, hope you understood...
Post by Pegasus [MVP]The code below is an example for your second question: How to assign each
line of the screen output to a variable. The text file d:\temp\test.txt
contains the exact console lines that you posted in your note.
@echo off
SetLocal EnableDelayedExpansion
set Line=0
for /F "delims=" %%a in ('type "d:\temp\test.txt"') do (
set /a Line=!Line! + 1
set Var=%%a
echo Line!Line!=!Var!
)
Now I have no time, but I will try ASAP. Thank you for this...
L.