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
    1. Advertisements

  2. Guest

    Wadester Guest

    In news:038f01c38d01$9c7a4b90$,
    <> posted:
    > 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...


    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.

    ws
     
    Wadester, Oct 7, 2003
    #2
    1. Advertisements

  3. Guest

    Bill Stewart Guest

    <> wrote:

    > 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.


    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
    #3
  4. Guest

    guard Guest

    <> wrote in message
    news:038f01c38d01$9c7a4b90$...> 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...


    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:

    %.GetIPAddr%
    ECHO:IP Address is %#IPAddr%

    *******

    For a color-keyed example, see
    (http://TheSystemGuard.com/MtCmds/GetValue/GetIPAddr.htm)

    *******

    -tsg
    ____________________________________________________________
    TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
    Free and "Almost Free" Knowledge for Windows System Admins!
     
    guard, Oct 7, 2003
    #4
  5. Guest

    Bill Stewart Guest

    guard <^T^S^G^n^e^w^s^@TheSystemGuard.com> wrote:

    > The Mount/Command ".GetIPAddr" CONSISTENTLY returns the IP Address under
    > NT/2K/XP/K3 and saves the value in variable "%#IPAddr%" for further use.


    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
     
    Bill Stewart, Oct 7, 2003
    #5
    1. Advertisements

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.
Similar Threads
  1. David Trimboli

    Detecting delayed environment variable expansion

    David Trimboli, Aug 29, 2003, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    0
    Views:
    929
    David Trimboli
    Aug 29, 2003
  2. Jimmy

    Export Environment Variable From a Cmd line VB Exe

    Jimmy, May 26, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    2
    Views:
    1,591
    Matt Hickman
    May 26, 2004
  3. Claus Koch

    Pipe Output into Environment Variable?

    Claus Koch, Aug 11, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    1
    Views:
    14,452
    Matthias Tacke
    Aug 11, 2004
  4. Nunayadam Bidnez

    carriage return in environment variable?

    Nunayadam Bidnez, Aug 29, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    1
    Views:
    1,484
    Matthias Tacke
    Aug 29, 2004
  5. Barney

    New Environment Variable?

    Barney, Sep 2, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    5
    Views:
    1,218
    Torgeir Bakken \(MVP\)
    Sep 3, 2004
  6. murdo

    Environment variable inside an environment variable

    murdo, Feb 24, 2005, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    7
    Views:
    3,454
    Mark V
    Feb 25, 2005
  7. Replies:
    7
    Views:
    2,552
    foxidrive
    Feb 28, 2007
  8. Guest

    set a variable to the output of a command

    Guest, Apr 10, 2007, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    4
    Views:
    1,617
    Timo Salmi
    Apr 11, 2007
Loading...