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

expect_out contains junk characters like unicode \u001b and other encodings like [00m

519 views
Skip to first unread message

shyam

unread,
Sep 19, 2007, 10:03:10 AM9/19/07
to
Hi All

This is a questing regarding expect

I composed a expect script to do some shell automation stuff and it
works perfectly fine.

I recently stumbled upon a problem which arises because i extract some
data from the expect_out buffer and store it in a tcl variable and
subsequently i pass the value of the variable to remote shell( via
expect) as part of another shell command argument.

I did a "exp_internal 1" and found that the data in expect_out buffer
is always prefixed and suffixed with some other encodings something
like this

expect: does "\u001b[00mtotal 8\r\n-rw-r--r-- 1 root root 0 Oct 19
19:18 \u001b[00mshh\u001b[00m\r\n-rw-r--r-- 1 root root 0 Nov 21
08:15 \u001b[00mshyam\u001b[00m\r\n\u001b[m\u001b]0;root@gsr39:/opt
\u0007[root@gsr39 opt]# "

I have to figure out a way to get rid of this leading and trailing
junk characters since this causes problems in some situations.

I guess, expect does not have any way to disable them so i feel i have
to filter them using some kind of tcl regsub or string command, but I
didnt have any success in that

Can some one suggest me a neat solution for this ??

Thanks in advance
Shyam

Glenn Jackman

unread,
Sep 19, 2007, 10:33:13 AM9/19/07
to
At 2007-09-19 10:03AM, "shyam" wrote:
> Hi All
>
> This is a questing regarding expect

It really looks like a question about your shell.

> I composed a expect script to do some shell automation stuff and it
> works perfectly fine.
>
> I recently stumbled upon a problem which arises because i extract some
> data from the expect_out buffer and store it in a tcl variable and
> subsequently i pass the value of the variable to remote shell( via
> expect) as part of another shell command argument.
>
> I did a "exp_internal 1" and found that the data in expect_out buffer
> is always prefixed and suffixed with some other encodings something
> like this
>
> expect: does "\u001b[00mtotal 8\r\n-rw-r--r-- 1 root root 0 Oct 19
> 19:18 \u001b[00mshh\u001b[00m\r\n-rw-r--r-- 1 root root 0 Nov 21
> 08:15 \u001b[00mshyam\u001b[00m\r\n\u001b[m\u001b]0;root@gsr39:/opt
> \u0007[root@gsr39 opt]# "

Looks like color coding. Try "ls --color=never".

Then again, if you want to get information about files, don't use "ls",
use the Tcl [file] command, particularly [file stat] and [file
attributes]


--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

shyam

unread,
Sep 19, 2007, 10:52:21 AM9/19/07
to

No , I have to use ls to retrieve files on the remote host so can't
use tcl commands


Further , I read in some old posts that if i run /bin/sh and then run
the ls and other commands then i do not see these junk characters.

This is ok for me, but still i would like to know how to use regsub od
expect's regexp to filter out these special characters.
More specifically i wanted to know how to form a regular expressions
using these special characters

Thanks

Glenn Jackman

unread,
Sep 20, 2007, 1:24:08 PM9/20/07
to
At 2007-09-19 10:52AM, "shyam" wrote:
> On Sep 19, 7:33 pm, Glenn Jackman <gle...@ncf.ca> wrote:
> > At 2007-09-19 10:03AM, "shyam" wrote:
> >
> > > expect: does "\u001b[00mtotal 8\r\n-rw-r--r-- 1 root root 0 Oct 19
> > > 19:18 \u001b[00mshh\u001b[00m\r\n-rw-r--r-- 1 root root 0 Nov 21
> > > 08:15 \u001b[00mshyam\u001b[00m\r\n\u001b[m\u001b]0;root@gsr39:/opt
> > > \u0007[root@gsr39 opt]# "
> >
> > Then again, if you want to get information about files, don't use "ls",
> > use the Tcl [file] command, particularly [file stat] and [file
> > attributes]
> >
>
> No , I have to use ls to retrieve files on the remote host so can't
> use tcl commands
>
> This is ok for me, but still i would like to know how to use regsub od
> expect's regexp to filter out these special characters.
> More specifically i wanted to know how to form a regular expressions
> using these special characters

You can just use them directly. To remove all \u001b and \u0007
characters, you can use one of :

regsub -all {[\u0007\u001b]} $str {} new_str

or

set new_str [string map {\u0007 "" \u001b ""} $str]

To additionally remove the "[00m] sequence:
regsub -all {[\u0007\u001b]|\[00m} $str {} new_str
or
set new_str [string map {\u0007 "" \u001b "" \[00m ""} $str]

0 new messages