Can't set an env variable via pipe

Jun 19, 2008
2
0
#1
If I write a BTM file that does this:
ECHO aaa | ECHO %@line[con,0]
it echos aaa. OK.

If I write a BTM file that does this
SET XXX=aaa
it sets the environment variable XXX as aaa. OK.

If I write a BTM file that does this:
ECHO aaa | SET XXX=%@line[con,0]
it doesn't set the variable xxx.

Why?

I want to set an env variable from the output of a program. In my test I simulated the program with ECHO aaa

Nick
 

rconn

Administrator
Staff member
May 14, 2008
10,588
97
#2
> If I write a BTM file that does this:
> ECHO aaa | ECHO %@line[con,0]
> it echos aaa. OK.
>
> If I write a BTM file that does this
> SET XXX=aaa
> it sets the environment variable XXX as aaa. OK.
>
> If I write a BTM file that does this:
> ECHO aaa | SET XXX=%@line[con,0]
> it doesn't set the variable xxx.
>
> Why?
It *does* set the variable -- but it sets it in the child pipe process, so
it's lost when the pipe exits.

If you're using v10, you can use the new "in-process" pipes; if you're using
v9 or earlier you'll have to save & read the value from a temp file.

Rex Conn
JP Software
 
Jun 19, 2008
2
0
#4
Rex: Thanks for the explanation. I have indeed used a temporary file as a work around.

Charles: EXCSTR looks like a good solution. I had forgotten about that - thanks.

Nick
 
#5
On Sun, 15 Feb 2009 08:16:37 -0600, rconn <> wrote:


>---Quote---
>> If I write a BTM file that does this:
>> ECHO aaa | SET XXX=%@line[con,0]
>> it doesn't set the variable xxx.
>>
>> Why?
>---End Quote---
>It *does* set the variable -- but it sets it in the child pipe process, so
>it's lost when the pipe exits.
>
>If you're using v10, you can use the new "in-process" pipes; if you're using
>v9 or earlier you'll have to save & read the value from a temp file.
Or use

SET XXX=%@EXECSTR[ECHO aaa]
--
- Vince
 
#6
On Sun, 15 Feb 2009 08:16:37 -0600, rconn <> wrote:


>---Quote---
>> If I write a BTM file that does this:
>> ECHO aaa | SET XXX=%@line[con,0]
>> it doesn't set the variable xxx.
>>
>> Why?
>---End Quote---
>It *does* set the variable -- but it sets it in the child pipe process, so
>it's lost when the pipe exits.
>
>If you're using v10, you can use the new "in-process" pipes; if you're using
>v9 or earlier you'll have to save & read the value from a temp file.
Or use

SET XXX=%@EXECSTR[ECHO aaa]
--
- Vince
 
#7
Nick Tatham wrote:
| Rex: Thanks for the explanation. I have indeed used a temporary file
| as a work around.
|
| Charles: EXCSTR looks like a good solution. I had forgotten about
| that - thanks.

It's @EXECSTR, and in V10 it is enhanced to allow selecting any line of the
output, not just the first.
--
HTH, Steve
 
#8
Nick Tatham wrote:
| Rex: Thanks for the explanation. I have indeed used a temporary file
| as a work around.
|
| Charles: EXCSTR looks like a good solution. I had forgotten about
| that - thanks.

It's @EXECSTR, and in V10 it is enhanced to allow selecting any line of the
output, not just the first.
--
HTH, Steve
 
#9
Nick Tatham wrote:
| Rex: Thanks for the explanation. I have indeed used a temporary file
| as a work around.
|
| Charles: EXCSTR looks like a good solution. I had forgotten about
| that - thanks.

It's @EXECSTR, and in V10 it is enhanced to allow selecting any line of the
output, not just the first.
--
HTH, Steve