expect_out buffer no such variable running script background

I am trying to use send and receive using expect. the expect_out(buffer) is working fine while it is running it as foreground. But the same script when it is ran as background, the expect_out(buffer) errored out.

Is there any factor influence when we run script in foreground and in background?

Please through some lights on this.

sample part of script

<..>
send "RTRV-COND-ALL:::P;";
expect ">"
set out $expect_out(buffer)
puts $out
<..>

---------- Post updated 10-01-10 at 11:04 AM ---------- Previous update was 09-30-10 at 11:37 PM ----------

Issue got fixed. The expect_out(buffer) is working fine while running in background...

It was an environmental issue.