expect's full_buffer doesn't seem to work 
Author Message
 expect's full_buffer doesn't seem to work

I'm trying to use the full_buffer expect pattern to save large outputs
that come before the final prompt in the output of a program. Even
though the buffer gets full, the full_buffer pattern never seems to
match. I wrote two small test programs that show this. Basically,
spew.tcl prints out a bunch of numbers ending with "done". try.exp
runs spew.tcl and waits for full_buffer or "done". At the end, try.exp
outputs the expect buffer. The expect buffer is always truncated, but
full_buffer never matches.

try.exp:
#!/usr/local/bin/expect -d
puts "COMMAND OUTPUT:"
spawn "./spew.tcl"
expect {
        "hello" {}
        full_buffer {puts "FULL BUFFER"}
        timeout {puts "TIMEOUT"}
        "done" {}

Quote:
}

puts "diddly"

puts "\n\n\n\n\n\nexpect_out(buffer):"
puts "$expect_out(buffer)"

spew.tcl:
#!/usr/local/bin/tclsh
puts "start"
for {set i 1} {$i < 2000} {incr i 1} {
        puts -nonewline "$i "

Quote:
}

puts "done"

Here's a portion of the output (sorry this is so long):
expect version 5.32.1
argv[0] = /usr/local/bin/expect  argv[1] = -d  argv[2] = ./try.exp  
set argc 0
set argv0 "./try.exp"
set argv ""
executing commands from command file ./try.exp
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {17408}

expect: does "" (spawn_id exp4) match glob pattern "hello"? no
"done"? no

expect: does "start\r\n" (spawn_id exp4) match glob pattern "hello"?
no
"done"? no

expect: does "start\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20 21 22
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
46 47 48 49
 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74 75 7
6 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
100 101 1
02 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
120 121 1
22 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
140 141 1
42 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
160 161 1
62 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
180 181 1
82 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
200 201 2
02 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
220 221 2
22 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
240 241 2
42 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
260 261 2
62 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
280 281 2
82 283 " (spawn_id exp4) match glob pattern "hello"? no
"done"? no
...
The end expect_out(buffer) contains "451" to "1999 done", but FULL
BUFFER is never printed.

Any ideas?
thanks,
Joe



Thu, 12 Aug 2004 15:35:20 GMT  
 expect's full_buffer doesn't seem to work

Quote:

> I'm trying to use the full_buffer expect pattern to save large outputs
> that come before the final prompt in the output of a program. Even
> though the buffer gets full, the full_buffer pattern never seems to
> match. I wrote two small test programs that show this. Basically,
> spew.tcl prints out a bunch of numbers ending with "done". try.exp
> runs spew.tcl and waits for full_buffer or "done". At the end, try.exp
> outputs the expect buffer. The expect buffer is always truncated, but
> full_buffer never matches.

> try.exp:
> #!/usr/local/bin/expect -d
> puts "COMMAND OUTPUT:"
> spawn "./spew.tcl"
> expect {
>  "hello" {}
>  full_buffer {puts "FULL BUFFER"}
>  timeout {puts "TIMEOUT"}
>  "done" {}
> }
> puts "diddly"

> puts "\n\n\n\n\n\nexpect_out(buffer):"
> puts "$expect_out(buffer)"

> spew.tcl:
> #!/usr/local/bin/tclsh
> puts "start"
> for {set i 1} {$i < 2000} {incr i 1} {
>  puts -nonewline "$i "
> }
> puts "done"

> Here's a portion of the output (sorry this is so long):
> expect version 5.32.1
> argv[0] = /usr/local/bin/expect  argv[1] = -d  argv[2] = ./try.exp  
> set argc 0
> set argv0 "./try.exp"
> set argv ""
> executing commands from command file ./try.exp
> parent: waiting for sync byte
> parent: telling child to go ahead
> parent: now unsynchronized from child
> spawn: returns {17408}

> expect: does "" (spawn_id exp4) match glob pattern "hello"? no
> "done"? no

> expect: does "start\r\n" (spawn_id exp4) match glob pattern "hello"?
> no
> "done"? no

> expect: does "start\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> 20 21 22
> 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
> 46 47 48 49
>  50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
> 73 74 75 7
> 6 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
> 100 101 1
> 02 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
> 120 121 1
> 22 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
> 140 141 1
> 42 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
> 160 161 1
> 62 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
> 180 181 1
> 82 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
> 200 201 2
> 02 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
> 220 221 2
> 22 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
> 240 241 2
> 42 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
> 260 261 2
> 62 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
> 280 281 2
> 82 283 " (spawn_id exp4) match glob pattern "hello"? no
> "done"? no
> ...
> The end expect_out(buffer) contains "451" to "1999 done", but FULL
> BUFFER is never printed.

> Any ideas?
> thanks,
> Joe

Have you tried send_user instead of puts?


Fri, 13 Aug 2004 00:37:58 GMT  
 expect's full_buffer doesn't seem to work

Quote:


> > I'm trying to use the full_buffer expect pattern to save large outputs
> > that come before the final prompt in the output of a program. Even
> > though the buffer gets full, the full_buffer pattern never seems to
> > match. I wrote two small test programs that show this. Basically,
> > spew.tcl prints out a bunch of numbers ending with "done". try.exp
> > runs spew.tcl and waits for full_buffer or "done". At the end, try.exp
> > outputs the expect buffer. The expect buffer is always truncated, but
> > full_buffer never matches.

> > try.exp:
> > #!/usr/local/bin/expect -d
> > puts "COMMAND OUTPUT:"
> > spawn "./spew.tcl"
> > expect {
> >  "hello" {}
> >  full_buffer {puts "FULL BUFFER"}
> >  timeout {puts "TIMEOUT"}
> >  "done" {}
> > }
> > puts "diddly"

> > puts "\n\n\n\n\n\nexpect_out(buffer):"
> > puts "$expect_out(buffer)"

> > spew.tcl:
> > #!/usr/local/bin/tclsh
> > puts "start"
> > for {set i 1} {$i < 2000} {incr i 1} {
> >  puts -nonewline "$i "
> > }
> > puts "done"

> > Here's a portion of the output (sorry this is so long):
> > expect version 5.32.1
> > argv[0] = /usr/local/bin/expect  argv[1] = -d  argv[2] = ./try.exp  
> > set argc 0
> > set argv0 "./try.exp"
> > set argv ""
> > executing commands from command file ./try.exp
> > parent: waiting for sync byte
> > parent: telling child to go ahead
> > parent: now unsynchronized from child
> > spawn: returns {17408}

> > expect: does "" (spawn_id exp4) match glob pattern "hello"? no
> > "done"? no

> > expect: does "start\r\n" (spawn_id exp4) match glob pattern "hello"?
> > no
> > "done"? no

> > expect: does "start\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> > 20 21 22
> > 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
> > 46 47 48 49
> >  50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
> > 73 74 75 7
> > 6 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
> > 100 101 1
> > 02 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
> > 120 121 1
> > 22 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
> > 140 141 1
> > 42 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
> > 160 161 1
> > 62 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
> > 180 181 1
> > 82 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
> > 200 201 2
> > 02 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
> > 220 221 2
> > 22 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
> > 240 241 2
> > 42 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
> > 260 261 2
> > 62 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
> > 280 281 2
> > 82 283 " (spawn_id exp4) match glob pattern "hello"? no
> > "done"? no
> > ...
> > The end expect_out(buffer) contains "451" to "1999 done", but FULL
> > BUFFER is never printed.

It's a bug - that part of the code wasn't internationalized properly.
Thanks for the sample script and clear bug report.  Here's the patch:

*** expect.c.old        Mon Feb 25 15:13:31 2002
--- expect.c    Mon Feb 25 15:37:39 2002
***************
*** 855,864 ****
        }
        expDiagLogU(no);
      } else if (e->use == PAT_FULLBUFFER) {
!       if ((Tcl_GetCharLength(esPtr->buffer) == esPtr->msize)
            && (length > 0)) {
-       expDiagLogU(Tcl_GetString(e->pat));
-       expDiagLogU("? ");
        o->e = e;
        o->match = length;
        o->buffer = esPtr->buffer;
--- 855,865 ----
        }
        expDiagLogU(no);
      } else if (e->use == PAT_FULLBUFFER) {
!       expDiagLogU(Tcl_GetString(e->pat));
!       expDiagLogU("? ");
!       /* this must be the same test as in expIRead */
!       if ((expSizeGet(esPtr) + TCL_UTF_MAX >= esPtr->msize)
            && (length > 0)) {
        o->e = e;
        o->match = length;
        o->buffer = esPtr->buffer;



Sat, 14 Aug 2004 04:41:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. re.LOCALE | re.IGNORECASE doesn't work as you'd expect

2. Expect question: interact -reset doesn't always seem to

3. set VIDEO_MODE_RESTRICTION=CGA doesn't seem to work

4. ios.gets doesn't seem to work as advertised

5. setting LD_LIBRARY_PATH doesn't seem to work?

6. proc doesn't seem to work in NASM

7. Micro Focus CALL-CONVENTION 8 doesn't seem to work

8. Adagide install doesn't seem to work?

9. Temporarily changing error_reporting()...doesn't seem to work

10. problem with exec: import doesn't seem to work

11. ldap.modify_s doesn't seem to work

12. update doesn't seem to work with scale

 

 
Powered by phpBB® Forum Software