ja...@nottheoilrig.com
unread,Jan 23, 2018, 1:53:49 PM1/23/18You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Is there a better way to accomplish the following?
> spawn -open [chan push [exp_open] [my_transform new]]
In other words, I want to filter the output of a command before operating on it with Expect.
Specifically I want to strip ANSI escapes from QEMU -curses, so I can script it with Expect. The UI running inside QEMU is plain text, the escapes are added by QEMU's virtual VGA device.
The code above doesn't error, but it doesn't work, either: Expect sees the original, un-filtered output. Here's a concise example:
> expect -c 'package require tcl::transform::base64; spawn echo Zm9v; spawn -open [chan push [exp_open] [tcl::transform::base64::implementation new]]; expect foo {puts bar};'
I expected that tcl::transform::base64 would decode Zm9v ("foo") and that Expect would then match it and print "bar". Actual output:
> spawn echo Zm9v
> spawn [open ...]
> Zm9v
I think the reason it doesn't work is that exp_command.c:884-940 grabs the underlying file descriptor and wraps a new Expect channel around it:
> 903: if (TCL_ERROR == Tcl_GetChannelHandle(channel, TCL_READABLE, &rfdc)) {
>
> 914: master = ((mode & TCL_READABLE)?rfd:wfd);
>
> 940: esPtr = expCreateChannel(interp,master,write_master,EXP_NOPID);
Then exp_chan.c:218 reads directly from the file descriptor:
> bytesRead = read(esPtr->fdin, buf, (size_t) toRead);