Pipe Output into Environment Variable?

Discussion in 'Microsoft Windows 2000 CMD Promt' started by Claus Koch, Aug 11, 2004.

  1. Claus Koch

    Claus Koch Guest

    Hi there

    i am looking for a way to pipe output of any command into a environment
    variable under w2k or XP.

    i don't want to go via a redirection by putting the Output into a text file
    first etc ...

    for example i want to search in a text file an put the result in a variable

    "findstr seachtext c:\testfile.txt"

    how can i put the result in a variable with the least effort ....

    thx in advance
     
    Claus Koch, Aug 11, 2004
    #1
    1. Advertisements

  2. "Claus Koch" wrote:

    >Hi there
    >
    >i am looking for a way to pipe output of any command into a environment
    >variable under w2k or XP.
    >
    >i don't want to go via a redirection by putting the Output into a text file
    >first etc ...
    >
    >for example i want to search in a text file an put the result in a variable
    >
    >"findstr seachtext c:\testfile.txt"
    >
    >how can i put the result in a variable with the least effort ....
    >
    >thx in advance
    >

    The intrinsic way of doing this is with a for loop.
    (works also with a temp file, but you don't have to care about)

    At the command line:
    for /f "delims=" %A in ('findstr searchtext') do @set YourVar=%A
    In a batch:
    for /f "delims=" %%A in ('findstr searchtext') do set YourVar=%%A

    If there is more than one findstr result, the last one is set.

    The free tool conset from Frank P. Westlake can do it this way:
    conset YourVar=`findstr searchtext`
    But the result may be a multiline var :)

    Hosted now by Ted Davis at http://gearbox.maem.umr.edu/fwu/

    HTH
    --
    Greetings
    Matthias________________________________________
    For help on nt commands enter in a cmd window:
    W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
     
    Matthias Tacke, Aug 11, 2004
    #2
    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. Roger Johnson

    pipe file input into command line command

    Roger Johnson, Aug 1, 2003, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    0
    Views:
    1,046
    Roger Johnson
    Aug 1, 2003
  2. 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
  3. Guest

    Set environment variable = output of exe

    Guest, Oct 7, 2003, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    4
    Views:
    1,977
    Bill Stewart
    Oct 7, 2003
  4. Aliyah

    Pipe the output

    Aliyah, Mar 4, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    3
    Views:
    610
    Aliyah
    Mar 5, 2004
  5. BaKaR

    For Function with Pipe Problem.

    BaKaR, Mar 24, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    10
    Views:
    890
    Paul R. Sadowski
    Mar 25, 2004
  6. Wensi Peng

    oExec.StdOut after pipe Findstr

    Wensi Peng, Jan 7, 2005, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    1
    Views:
    771
    Matthias Tacke
    Jan 7, 2005
  7. 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
  8. Replies:
    7
    Views:
    2,552
    foxidrive
    Feb 28, 2007
Loading...