Capture output from expect script

Hi

I am new to Expect scripting. I have to connect to a remote server and capture the output. Here I need output of " send "list registered\r"" to be stored in a file. but after execution, /tmp/capture.txt is of 0 byte

#!/usr/bin/expect
spawn ssh abc@10.10.10.10 -p 5022
        expect "Password:"
        send "xyz123\r"
        send "W2KTT\r"
        send "list registered\r"
set var $expect_out(buffer);
set fid [open /tmp/capture.txt w]
puts $fid $var
interact

Can you please help me in fixing this

Assumption your prompt contains one of (#$%)

#!/usr/bin/expect
match_max 100000
spawn ssh abc@10.10.10.10 -p 5022
        expect "Password:"
        send "xyz123\r"
        send "W2KTT\r"
        expect -re "\[#\$%]"
        send "./list registered\r"
expect -re "registered\r\n(.*)\r\n\[^\r]*\[#\$%]"
set var $expect_out(1,string)
set fid [open /tmp/capture.txt w]
puts $fid $var
interact

I smell an Avaya guy!

Did anything ever come of your attempts to automate this?