PDA

View Full Version : Issues passing escape signals in expect



floobit
April 5th, 2012, 06:30 PM
I'm trying to navigate an ncurses-based text interface using expect. I need to send escape sequences in order to do so. I'm having trouble doing so. I want to send an <F4> signal, which in xterm is <esc>[OS. I have used od -c to verify this, and sure enough, if I type <ctrl>[ then O, then S from within the interface, I get the desired behavior. Documentation I've read says that I can use send "\cX" to send the <ctrl>-X signal. I've used this in the sample below:



#!/usr/bin/expect
spawn interface.ui
set timeout -1
expect "Welcome"
send "user\r"
set timeout -1
expect "user"
send "password\r"
set timeout -1
expect "Main Menu"
send "\c[OS"


Upon execution of this script, after the escape code is sent, all the characters are garbled when printed onto the screen:


⎽⎽␋┼ ␌┌⎺⎽␊-␉⎼▒␌┐␊├
┬␤␋┌␊ ␊│␊␌┤├␋┼
"⎽␊┼␍ "\␌[OS"
⎽␊├ ├␋└␊⎺┤├ -1
␊│⎻␊␌├ "M▒␋┼ M␊┼┤"
⎽␊┼␍ "≤\⎼"


␋┼├␊⎼▒␌├

"
(␋┌␊ "./├␊⎽├.␊│" ┌␋┼␊ 25)
␍␊┴2:[/␉␋┼]$


Thoughts? I tried to write an expect sequence to write characters into od -c (to test whether the correct sequence is being sent), but expect won't write anything to the od -c line.