|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Batch File: For Loop Help!!!!!!!!!!
Here we go:
I have the following batch file: Code:
ipconfig | find "IP Address. . . . . . . . . . . . : 10" > ip1.txt for /f "tokens=1-2 delims=:" %i in (ip1.txt) do echo %%j >ip2.txt for /f "tokens=1-4 delims=." %i in (ip2.txt) do set IPADDR= %i.%j.%k.%l echo %username%, %computername%, %date%,%time%,%IPADDR%,LOGGED ON>>\\servername\data\audit\LOGON_LOGOFF_EVENTS.txt On a windows xp machine this works fine if you past it into a command prompt. You can test the following code by just pasting into a command prompt or cmd prompt: You will see that it works as advertised ... Code:
ipconfig | find "IP Address. . . . . . . . . . . . : 10" > ip1.txt for /f "tokens=1-2 delims=:" %i in (ip1.txt) do echo %%j >ip2.txt for /f "tokens=1-4 delims=." %i in (ip2.txt) do set IPADDR= %i.%j.%k.%l echo %username%, %computername%, %date%,%time%,%IPADDR%,LOGGED ON Here's the But: If I run it using the batch file it produces this error: C:\>ipconfig | find "IP Address. . . . . . . . . . . . : 10" 1>ip1.txt j was unexpected at this time. C:\>for /f "tokens=1-2 delims=:" j >ip2.txt) Any suggestions ??? |
|
#2
|
|||
|
|||
|
For loop variables in batch files must use double-percent i.e. %%J
At the command prompt use %J In a batch file use %%J |
![]() |
| Viewing: Web Development Archives > FAQs > MS DOS > Batch File: For Loop Help!!!!!!!!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|