How to get ouput from expect

Posted by Mallikarjunarao on Stack Overflow See other posts from Stack Overflow or by Mallikarjunarao
Published on 2010-06-07T11:31:10Z Indexed on 2010/06/08 11:02 UTC
Read the original article Hit count: 320

Filed under:

i wrote a script for spawing the bc command

package require Expect

proc bc {eq} {
    spawn e:/GnuWin32/bc/bin/bc
    send "$eq\r"
    expect -re "(.*)\r"
    return "$expect_out(0,string)"
}

set foo "9487294387234/sqrt(394872394879847293847)"

puts "the valule [bc $foo]"

how to get the output from this. When i am running this one i get ouput like this

bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
9487294387234/sqrt(394872394879847293847)
477
can't read "expect_out(0,string)": no such element in array
    while executing
"return "The values is $expect_out(0,string)""
    (procedure "bc" line 6)
    invoked from within
"bc $foo"
    invoked from within
"puts "the valule [bc $foo]""
    (file "bc.tcl" line 21)

how to resolve this one.

© Stack Overflow or respective owner

Related posts about tcl