Set environment variable from stdout of command

Aug 7, 2009
50
0
In a batch file, using sed to extract a string from a file (sed writes its output to stdout), I would like to set an environment variable to that extracted string. Is that possible?

Eg. from a Windows scheduled task xml file, which contains the line:

<spaces><Author>Papa\burger</Author><nl>

using the sed command:

sed -n -e"s/^.*<Author>\([a-zA-Z0-9_]*\)\\[a-zA-Z0-9_]*<\/Author>$/\1/ip" filename.xml

produces the output:

Papa<nl>

How to set environmentvariable=Papa?
 
May 20, 2008
9,144
58
Syracuse, NY, USA
In a batch file, using sed to extract a string from a file (sed writes its output to stdout), I would like to set an environment variable to that extracted string. Is that possible?

Eg. from a Windows scheduled task xml file, which contains the line:

<spaces><Author>Papa\burger</Author><nl>

using the sed command:

sed -n -e"s/^.*<Author>\([a-zA-Z0-9_]*\)\\[a-zA-Z0-9_]*<\/Author>$/\1/ip" filename.xml

produces the output:

Papa<nl>

How to set environmentvariable=Papa?
Code:
SET environmentvariable=%@execstr[sed -n -e"s/^.*<Author>\([a-zA-Z0-9_]*\)\\[a-zA-Z0-9_]*<\/Author>$/\1/ip" filename.xml]
 
Aug 7, 2009
50
0
Thanks once again, Steve and Vince, for prompt and helpful replies. I had thought of using a temporary file, but that was as far as I got. But @execstr[] is perfect for the task, it does exactly what I needed (in fact, an example in the help file even shows using it to set an environment variable!).