title: how to clean up the previous expect_buf in an expect script
body: <p>I've written a expect function to get the output of a command and my code is like below</p>
  
  <pre><code>proc do_cmd {cmd id} {
    set spawn_id $id
    send "$cmd\r"
    expect "$cmd\r"
    expect {
      -re "\n(.*)\r\n" {return $expect_out(1,string)}
      default {exit 1}
    }
  }
  </code></pre>
  
  <p>If I call the function just once it would works fine and return something I want, but if I call it continually without a break, it would return something unwanted.</p>
  
  <pre><code># test case 1
  set ret [do_cmd $mycmd $spawn_id]
  puts "$mycmd returns $ret"  # the return value is ok
  
  # test case 2
  set ret [do_cmd $mycmd $spawn_id]
  set ret [do_cmd $mycmd $spawn_id]
  puts "$mycmd returns $ret"  # the return value is not something I want
  </code></pre>
  
  <p>I use the 'exp_internal 1' to debug it and found that the expect_out in the second called command still holds the previous output info and caused the matched problem, so how can I clean up the expect_out buffer(I tried to set it an empty string but it doesn't work,) or is there anything else I can do to avoid this problem? Thanks in advance.</p>