Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass value to a variable.

Status
Not open for further replies.

max1x

Programmer
Jan 12, 2005
366
US
I'm a complete novice to the this and here's what I'm trying to do:

capture the value of
Code:
send "set | grep TZ"
to a variable.

I tried
Code:
set tzVal [send "set | grep TZ"]
puts $tzVal
but it seems to be completely off base here

I am also unable to print expect_output(buffer), getting a not initialized value error. Any help would be much appreciated.
 
Actually, I think your syntax should work. What does "puts $tzVal" show?

Try set tzVal [eval [send "set | grep TZ"]]

_________________
Bob Rashkin
 
When I run the script I get:

Code:
set val [exp_send "set | grep TZ\r"]
expect "\$"
puts "val is $val"

Code:
$ set | grep TZ
TZ=US/Central
$ val is

With eval I get the following error message:

Code:
set val [eval[exp_send "set | grep TZ\r"]]
expect "\$"
puts "val is $val"
Code:
wrong # args: should be "eval arg ?arg ...?"
    while executing
"eval[exp_send "set | grep TZ\r"]"
    invoked from within
"set val [eval[exp_send "set | grep TZ\r"]]"
 
my mistake.

I think the "eval" statement should be:
set val [eval exp_send "set | grep TZ\r"]

_________________
Bob Rashkin
 
tried it still didn't work. Still working on it.
 
Well, I don't know any Expect and I expect that's where the problem is.

_________________
Bob Rashkin
 
I ended up using procs for my specific needs.

Thx for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top