Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to remove special control characters in expect_out(buffer)

122 views
Skip to first unread message

Rajesh Kumar TV

unread,
Jul 13, 2015, 8:39:53 PM7/13/15
to
Hi All,
I want to know how to remove special control characters from expect_out(buffer);



For example:

^[[0;32mIn [^[[1;32m2^[[0;32m]: ^[[0m




^[[0;32mIn [^[[1;32m4^[[0;32m]: ^[[0m





^M^[[0;32mIn [^[[1;32m4^[[0;32m]: ^[[0



Please let me know.

Thanks
Rajesh

heinrichmartin

unread,
Jul 14, 2015, 4:56:29 AM7/14/15
to
On Tuesday, July 14, 2015 at 2:39:53 AM UTC+2, Rajesh Kumar TV wrote:
> I want to know how to remove special control characters from expect_out(buffer);

Hi Rajesh,

there is nothing like a pre-processing filter in Expect - i.e. you cannot modify the buffer _before_ the pattern matching. Depending on where the control characters come from, you have various options - here are the ones that came to my mind instantly:

* change the prompt of the spawned shell (if it is the prompt only)
* use command line options for the output format OR pipe the output through ansifilter[1]
* find a regular expression for "all escape sequences"[2] and use regsub (if removing them _after_ pattern matching is sufficient)

HTH,
Martin

[1] http://andre-simon.de/doku/ansifilter/en/ansifilter.php
[2] Your examples include escape sequences [http://ascii-table.com/ansi-escape-sequences.php], not just control charaters [0x00~0x1F].

Alexandru

unread,
Jul 14, 2015, 7:14:16 AM7/14/15
to
Am Dienstag, 14. Juli 2015 02:39:53 UTC+2 schrieb Rajesh Kumar TV:
> Hi All,
> I want to know how to remove special control characters from expect_out(buffer);
>
>
>
> For example:
>
> ^[[0;32mIn [^[[1;32m2^[[0;32m]: ^[[0m

Isn't string map do the job? E.g.:

string map {^ "" \[ "" \] ""} {^[[0;32mIn [^[[1;32m2^[[0;32m]: ^[[0m}

Rich

unread,
Jul 14, 2015, 10:40:32 PM7/14/15
to
^[ is not ^ followed by [, it is the terminal representation of an Esc
character (code 27 decimal). The terminal output driver converts "Esc"
to display as ^[, but within the buffer, it will be a single byte of
27.

Provided all the escape codes are consistent, you could string map them
all away. But there are a lot of different combinations if the output
program is dynamically changing what it outputs.

Best would be to convince the output program to stop outputting
terminal control codes.
0 new messages