Set environment variable = output of exe

Discussion in 'Microsoft Windows 2000 CMD Promt' started by Guest, Oct 7, 2003.

  1. Guest

    Guest Guest

    I have a simple dos program that returns the IP address
    of the host it is run on. I want to setup an environment
    variable to be assigned the value of the IP address
    returned by this program:

    For example...

    set ipaddress = | ipclient.exe

    I was hoping this would make the environment variable
    equal to the IP address of my client but it does not work.

    Any suggestion? TIA...
    Guest, Oct 7, 2003
    1. Advertisements

  2. Guest

    Wadester Guest

    Try this:

    for /f "tokens=*" %i in ('ipclient.exe') do set ipaddress=%i

    In a batch file, substitute %%i for %i.

    Depending on what output ipclient.exe has, you may have to play with the
    "tokens=" setting.

    Wadester, Oct 7, 2003
    1. Advertisements

  3. Guest

    Bill Stewart Guest

    You're right -- the above command pipes the result of the command 'set
    ipaddress =' to the executable ipclient.exe.

    I think you want to do this:

    for /f %%a in ('ipclient') do set IPADDRESS=%%a
    Bill Stewart, Oct 7, 2003
  4. Guest

    guard Guest

    I have a simple dos program
    that returns the IP address
    The Mount/Command ".GetIPAddr" CONSISTENTLY returns
    the IP Address under NT/2K/XP/K3 and saves the value
    in variable "%#IPAddr%" for further use.

    For example:

    ECHO:IP Address is %#IPAddr%


    For a color-keyed example, see


    ____________________________________________________________ | |
    Free and "Almost Free" Knowledge for Windows System Admins!
    guard, Oct 7, 2003
  5. Guest

    Bill Stewart Guest

    Hi John ("guard"),

    We all really wish you would listen to our advice instead of stubbornly
    ignoring it. Or is it your goal to irritate people?

    Please do not crosspost to newsgroups that do not pertain to the subject
    matter and platform in question. In case you don't understand what this
    means, alt.msdos.batch is not the place for NT-related shell scripting
    using cmd.exe. That should be obvious, but evidently it's not.

    You are also cross-posting to other newsgroups, but this is considered bad
    etiquette. The question was asked in one newsgroup; please answer it in the
    same newsgroup without spamming the others.

    Also, in case you haven't noticed already, these newsgroups are not the
    place to market your "products." All you are doing is annoying the regulars
    and getting a bad name for yourself. Please stop insulting us with your
    "rise above the rest" nonsense.

    Bill Stewart, Oct 7, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.