Expect: Changing locale causes spawned process to exit

From FVue
Jump to: navigation, search

Problem

I'm using `expect' to test bash. When bash has its locale set to `en_US.UTF-8' and this locale is changed within the `expect' script to `LC_CTYPE=C' and a unicode character is send, `expect' incorrectly detects end of file (eof), causing subsequent `sends' to yield an error:

send: spawn id exp6 not open

Steps to reproduce the problem

1. Create a file unicode.exp containing:

spawn bash
send "LC_CTYPE=C\r"
send "aaébb";    # unicode é = \u00e9
expect -ex "cc"; # 'expect' detects eof when reading \u00e9?
send "dd";       # 'expect' error: spawn id not open

2. Run: LC_CTYPE=en_US.UTF-8 expect -f unicode.exp

3. I get this error output:

$ expect -f unicode.exp
spawn bash
LC_CTYPE=C
aaébb$ LC_CTYPE=C
$ aasend: spawn id exp6 not open
    while executing
"send "dd""
    (file "unicode.exp" line 6)

4. What I expected is the same output as with LC_CTYPE=C expect -f unicode.exp:

$ LC_CTYPE=C expect -f unicode.exp
spawn bash
LC_CTYPE=C
aaébb$ LC_CTYPE=C
$ aaC)bb$ 

Environment

  • Debian-5.0.6 (lenny)
  • expect-5.43.0 (expect -v)
  • tcl-8.4.19 (tclsh, info patchlevel)

Error also occurs on expect-5.44.1.15 and tcl-8.5.9.

Workaround

Change the LC_CTYPE not within, but outside the `except' script:

$ cat unicode2.exp
spawn bash
send "aaébb"
expect -ex "cc"
send "dd"
$ LC_CTYPE=C expect -f unicode.exp

Journal

2010-10-17

Compiled expect-5.44.1.15 and tcl-8.5.9 on Debian, but same error occurs.

2010-10-16

I cannot reproduce the problem on another (faster) machine Ubuntu-10.04 (Lucid Lynx) with expect-5.44.1.14 and tcl-8.4.19.

Comments

blog comments powered by Disqus