Pipe Output into Environment Variable?

  • Thread starter Thread starter Claus Koch
  • Start date Start date
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
 
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
 
Back
Top