Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: fd2580f80471fcc91f8ceb7b89ddebc066fa252c
Ticket: 30c5d37cfa0028c9ef83fa9efc490f4bc28b64ff
Expect eof occurring before end of output from spawned process
User & Date: tld on 2013-08-13 20:22:51
Changes

  1. icomment:
    Oh man...makr, you may have saved me big time on this one.
    
    I had read all that about the full_buffer etc.  Here's what had me confused:  As you can see in my example, I was relying on "log_user 1" to send the output of the spawned process.  What confused me about what I'd seen regarding full_buffer is that there was no question that with large output, I was likely getting full buffers maybe hundreds of times...however the text was in fact getting output by the script based on log_user 1.  Apparently however, relying on that is a mistake, as it can get tripped up by the last full buffer, loosing the end of the output.
    
    I just tested the following change: a) leaving log_user at 0, b) adding a full_buffer that does "puts -nonewline $expect_out(buffer)", and c) adding that same puts statement to the eof block before exiting.  As far as I can tell so far, that works perfectly.
    
    Thanks so much for that.  Wish I'd looked into it more carefully before.  Here's the working test script:
    
    set timeout 30
    
    proc exitspawnstat args {
       catch wait result
       set rtn [lindex $result 2]
       if { !$rtn } {
          set rtn [lindex $result 3]
       }
       exit $rtn
    }
    
    log_user 0
    set stty_init raw
    spawn -noecho cat ./in.txt
    expect {
       eof {
          puts -nonewline $expect_out(buffer)
          exitspawnstat
       }
       full_buffer {
          puts -nonewline $expect_out(buffer)
          exp_continue
       }
       timeout {
          log_user 1
          send_user "Timeout.\n"
          exit 253
       }
       -nocase -re "password:" { 
          exp_continue
       }
       "(yes/no)? " { 
          exp_continue
       }
       -nocase -re "Enter passphrase" {
          exp_continue
       }
       "testing-sudo-passwd:" {
          exp_continue
       }
    }
    
  2. login: "tld"
  3. mimetype: "text/plain"