Pipe Output into Environment Variable?

C

Claus Koch

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
 
M

Matthias Tacke

Claus Koch said:
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top