Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Need help with tokens  (Read 3606 times)

0 Members and 1 Guest are viewing this topic.

lkarelee

    Topic Starter


    Starter

    Need help with tokens
    « on: June 24, 2008, 09:06:53 AM »
    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 [email protected] -subject "PROBLEM WITH %%j"  -attach -q -priority 1 -mailfrom [email protected] -replyto [email protected] -noh2 -r -d) else (ECHO Site Resonding:%ERRORLEVEL%

    Dias de verano

    • Guest
    Re: Need help with tokens
    « Reply #1 on: June 24, 2008, 10:07:19 AM »
    Since we are not telepathic, an example of icu.txt would be nice.

    lkarelee

      Topic Starter


      Starter

      Re: Need help with tokens
      « Reply #2 on: June 24, 2008, 10:10:07 AM »
      sorry about that.....

      10.121.48.5,AF40 
      10.114.48.6,AF42

      Dias de verano

      • Guest
      Re: Need help with tokens
      « Reply #3 on: June 24, 2008, 10:35:33 AM »
      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 [email protected] -subject "PROBLEM WITH
      set errprogparam2="  -attach -q -priority 1 -mailfrom [email protected] -replyto [email protected] -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!



      lkarelee

        Topic Starter


        Starter

        Re: Need help with tokens
        « Reply #4 on: June 24, 2008, 12:48:52 PM »
        that works great - Thanks!!