TCL in IOS - how to insert a carriage return

Unanswered Question
Aug 6th, 2010
User Badges:


I have a very simple TCL script which clears the lines on a terminal server:

puts [open "flash:clear2" w+] {
puts "Clearing line 33"
puts [exec "clear line 33"]
puts "Clearing line 34"
puts [exec "clear line 34"]
.   (etc.)
puts "Clearing line 46"
puts [exec "clear line 46"]

It works fine except that I have to press enter for each line.  The router's responds to the "clear line" command with a " [confirm] " and waits for the enter key to be hit.  I'd like to automate this and was looking for a way to respond to the " [confirm] " within the script.  I thought maybe a "catch" would work but can't seem to find a link that explains how to accomplish this.  Anyone know how to do this?

Thanks in advance!


  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 0 (0 ratings)
gespahl Tue, 08/10/2010 - 06:21
User Badges:

No, that doesn't seem to do it although now I see the "[confirm] " and "[OK]" after I hit the enter key.  I tried adding a second typeahead as well but no luck.  Thanks all the same though.


Joe Clarke Fri, 08/13/2010 - 23:11
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

You want:

typeahead "y" ; exec "clear line 37"

mushamim Thu, 01/29/2015 - 18:45
User Badges:
  • Cisco Employee,

I hacked a way to make carriage return in tclsh work. You will need the following two lines after your command line needing a carriage return (and sometimes a set before the command as well):


typeahead "\r"


So, for instance, to do a repeated tclsh copy tftp command that requires CR, I use in tclsh script:



typeahead "\r"

copy tftp:// flash:largefile


typeahead "\r"



This works fine even in a loop.

The line with r will causes "No open connections" message on CLI of no known consequences. The typeahead text is saved in the buffer and entered as user-typed input on the command line after the tclsh script command completes.


cscbrannent Wed, 12/16/2015 - 08:13
User Badges:

I googled the carriage return issue, and we're trying to do the same thing.

This is working for me, on a  3725 with 12.4(25):

for {set i 33} {$i < 49} {incr i} {
      typeahead "\r";clear line $i}


This Discussion

Related Content