Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Can't set an env variable via pipe

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
 
> 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
 
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.

If you just need the first (only?) line of output, there is also the handy @EXECSTR function. Think of it as a sort of reversed pipe.

Code:
set xxx=%@execstr[echo aaa]
 
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
 
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
 
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
 
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
 
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
 
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
 

Similar threads

Replies
4
Views
2K
Back
Top