Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
Output is not clear

Posted by sanpraka (sanpraka), 1 April 2006
hi experts,

i am new to expect.when i logged into the remote device and executed the command in ls -l.the output is captured in a file but there are some special characters in between the lines.can u please help me out in eliminating these characters from this ouput.

This is my script:
#!/usr/bin/expect -f
set filename "/tmp/logfile.txt"
set fileid [open $filename "w"]
set force_conservative 1
set match_max 100000
exp_internal 1
set timeout -1
set TASK "$argv\r"
set USER  [lindex $TASK 1]
set SERVER [lindex $TASK 0]
set PASSWD [lindex $TASK 2]
spawn ssh $SERVER -l $USER
expect "root@'s password:"
send "$PASSWD\r"
sleep 5
expect "#"
send "ls -l\r"
expect "#"
set tempvar $expect_out(buffer)
puts $fileid $tempvar;
send "exit\r"
close $fileid

Here is the Sample output:

ls -l^M
^[[00mtotal 120^M
-rw-------  1 root root   798 Mar 17 17:05 ^[[00manaconda-ks.cfg^[[00m^M
-rw-r--r--  1 root root    37 Mar 17 17:12 ^[[00mbirthdate^[[00m^M
drwxr-xr-x  2 root root  4096 Mar 20 16:36 ^[[00;34mDesktop^[[00m^M
-rw-r--r--  1 root root 71590 Mar 17 17:05 ^[[00minstall.log^[[00m^M
-rw-r--r--  1 root root  9737 Mar 17 17:05 ^[[00minstall.log.syslog^[[00m^M^[[m^[]0;root@localhost:~^G[root@localhost ~]#

Please help me out by gving a fast reply.i will be very much thankful.


Posted by admin (Graham Ellis), 1 April 2006
The extra characters are a terminal control sequence that's sent out by your remote host to provide formatting.  If you set the terminal type for your session to DUMB, you should be able to prevent the problem. Do so via the login's .bashrc file or via an export command that's a part of your sequence if you're using the bash shell ... the commands / files vary a bit for other shells.

Sanjeev, welcome to Opentalk. You write "Please help me out by gving a fast reply" I have a target of making technical comment (at least) on 90% of questions within 24 hours, and I always get back quicker if I can. I prioritise questions raised by people who give (i.e. help answering questions) as well as take, and questions raised by people I have trained (for whom the service was created in the first place). If you are not in one of these groups and require a faster support service, you can buy it; have a look here for example - "Entry P4" lists a contract at $2500 per annum with 24 hour emergency support available on an additional time and materials basis. However, that is not something I can provide.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho