title: using expect to loop over output and send to file
body: <p>i am trying to use expect to log into an appliance, fetch the config, and write it to a file (i can't use ssh keys, appliance doesn't support it, and the thing actually has two logins). </p>
  
  <p>the problem is when i use this, the data is truncated (i only get the last ~100 lines of the config file):</p>
  
  <pre><code>...snip...
  match_max 100000
  set timeout 150
  set output [open "outputfile.txt" "w"]
  set config $expect_out(buffer)
  puts $output $config
  close $output
  ...snip...
  </code></pre>
  
  <p>so now, per a suggestion i read somewhere, i am trying to use expect to loop over the output, one line at a time, but i can't get the data to output like i could without the loop. here is the code that is not working. the config is ~700 lines.</p>
  
  <pre><code>#!/usr/bin/expect
  match_max 50000
  spawn ssh admin@192.168.1.10
  expect "password"
  send "password1\r"
  expect "user"
  send "root\r"
  expect "password"
  send "password2\r"
  
  set outcome {}
  set writeout [open "outputfile.txt" "w"]
  
  expect "device"
  exp_send "show running\r"
  expect {
          -regexp {.*}{
          set outcome "${outcome}$expect_out(0,string)"
          exp_continue
          }
  }
  puts $writeout $outcome
  close $writeout
  
  expect "device"
  send "exit\r"
  send "yes\r"
  </code></pre>
  
  <p>any help would be greatly appreciated. let me know if you need any more information. </p>
  
  <p>thanks!</p>