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
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
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
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]