Version 4 of Pipes vs Expect

Updated 2002-08-12 14:49:30

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 does this really work? On Windows and Unix? 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?