Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 722ca69b51ec961f8ba1f6d71f3d32ebc0bc1ae3
Ticket: 30c5d37cfa0028c9ef83fa9efc490f4bc28b64ff
Expect eof occurring before end of output from spawned process
User & Date: tld on 2013-08-02 19:39:53
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    I've never logged a ticket here.  Apologies if I get something wrong.
    
    We initially noticed this behavior in expect scripts that were getting data from commands run on remote systems via ssh, but I've been able to duplicate the behavior in very simple expect scripts that simply spawn a process that uses cat to output a file.
    
    The behavior is somewhat unpredictable but my tests reproduce it much more often then not.  What happens is that within an expect block, only in cases where the expect block does pattern matching of any kind, an eof can occur before all the data is output by the spawned command, thus truncating the output.
    
    I cannot reproduce this on an older CentOS 5 system running tcl-8.4.13 (and expect-5.43.0-8).  I can however reproduce it on any system I've tried using tcl 8.5, including CentOS 6 (tcl-8.5.7-6.el6.x86_64, expect-5.44.1.15-4.el6.x86_64) and on an x86 Gentoo system (dev-lang/tcl-8.5.13-r1 and dev-tcltk/expect-5.44.1.15).
    
    As mentioned above, this only occurs if the expect block has patterns in addition to the eof.  I've pasted a test script below that spawns "cat ./in.txt".  I've been testing with that using:
    
    expect test.expect > out.txt
    
    ...and then...
    
    diff -w in.txt out.txt
    
    ...which will show that the output was truncated.  I can reproduce this on files as small as 1000 lines and around 40-50k, with no text that would match any of the patters, and it appears that it's more likely to occur if match_max is reduced.
    
    Here is the test script.  Note that some the original patterns have been left in, but don't actually need to match any text:
    
    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 1
    spawn -noecho cat ./in.txt
    expect {
       eof {
          exitspawnstat
       }
       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
       }
       "arx-sudo-pwd:" {
          exp_continue
       }
    }
    
  5. foundin changed to: "tcl-8.5.7"
  6. is_private changed to: "0"
  7. login: "tld"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "1b4acbf8a1b26ad481e69c77816a02d377bac5a2"
  10. resolution changed to: "None"
  11. severity changed to: "Severe"
  12. status changed to: "Open"
  13. submitter changed to: "tld"
  14. subsystem changed to: "16. Commands A-H"
  15. title changed to:
    Expect eof occurring before end of output from spawned process
    
  16. type changed to: "Bug"