Version 5 of Pipes vs Expect

Updated 2002-08-13 12:55:55

the page is to discuss ways in which pure-Tcl can be used to do some of the simpler things one might otherwise want to use Expect for. My testing lends me to believe there is actually very little in this category, but this contradicts what is written elsewhere.

For example, in CVS it is stated that:


...ways to use cvs...

      [open "|cvs -d $cvsroot init" RDWR] and talking to
      cvs along pipes.

Will this really work? If cvs asks for my password, can I really check for that and send it back down the pipe?

Well, yes, you can. If however there is going to be very much interaction, or if the strings being examined are going to be very complex, I (LV) would recommend looking at Expect as a Tcl extension to make the interaction a bit easier.


But I can't get anything like this to work on Windows or Unix, and I've yet to see a code snippet which actually does this. I understand that for complex uses Expect is obviously the way to go, but if all I want to do is make sure 'cvs' gets my password, it sounds like it would be easy enough just to use pure Tcl. I've tried the following code, but it fails to do anything sensible...

    cd c:/tcl-source/tcl
    console show
    update

    proc go {} {
        set pipe [open "|cvs -z5 update ChangeLog" RDWR]
        fconfigure $pipe -buffering none -blocking 1
        fileevent $pipe readable [list piperead $pipe]
        fileevent $pipe writable [list pipewrite $pipe]
        return $pipe
    }

    global gotpass

    proc piperead {pipe args} { 
        global gotpass
        if {![eof $pipe]} {
            puts "read $pipe : $args" 
            set gotpass [gets $pipe]
            puts "got: $gotpass"
        }
        update idletasks
    }
    proc pipewrite {pipe args} { 
        global gotpass
        if {[info exists gotpass]} {
            puts "write $pipe : $args" 
            puts $pipe "mypassword"
        }
        update idletasks
    }

    go

Any ideas?