1.

Solve : Need help with tokens?

Answer»

I am NOT a DOS programmer - but I need some help writing this simple utility. I want the batch to read
a file (icu.txt) and pass two parameters to a command (%%i"ip" and %%j"location")- here is what I have so far - EVERYTHING works except it doesn't pass the IP address to the executable - it just shows up as "%i" - I appreciate any help you can give.

setlocal EnableDelayedExpansion
FOR /F "tokens=1,2 delims=," %%i IN (icu.txt) do call :hello
:hello
d:\scheduled\icu_hello\send_message_to_ip.exe %%i 3046 HELLO
if %ERRORLEVEL% neq 0 (c:\g\glh\blat d:\scheduled\icu_hello\message.txt -to [emailprotected] -subject "PROBLEM WITH %%j" -ATTACH -q -PRIORITY 1 -mailfrom [emailprotected] -replyto [emailprotected] -noh2 -r -d) else (ECHO Site Resonding:%ERRORLEVEL%Since we are not telepathic, an example of icu.txt would be nice.
sorry about that.....

10.121.48.5,AF40
10.114.48.6,AF42
This is just a quick hack, and as I don't have send_message_to_ip.exe I can't properly test it, but I believe I have mostly sorted out the batch logic and simplified things a bit.


Code: [Select]@echo off
setlocal EnableDelayedExpansion
set errprogname=c:\g\glh\blat
set errprogparam1=d:\scheduled\icu_hello\message.txt -to [emailprotected] -subject "PROBLEM WITH
set errprogparam2=" -attach -q -priority 1 -mailfrom [emailprotected] -replyto [emailprotected] -noh2 -r -d
for /F "tokens=1,2 delims=," %%i IN (icu.txt) do (
d:\scheduled\icu_hello\send_message_to_ip.exe %%i 3046 HELLO
set /a err=!errorlevel!
if !err! neq 0 (
%errprogname% %errprogparam1% %%j%errprogparam2%
) else (
echo Site Responding:!err!
)
)
Notes:

1. Double-percent variables such as %%i and %%j are loop variables. They only exist IN A LOOP. Your "subroutine" at the label HELLO is outside the loop so therefore cmd.exe strips off the first percent sign and passes the rest on.

2. Since you have ENABLED delayed expansion you may as well use it!


that works great - THANKS!!



Discussion

No Comment Found