AnsweredAssumed Answered

tclsh - enable raw input on tty

Question asked by sebastianmuesch on May 20, 2014
Latest reply on Jun 1, 2014 by sebastianmuesch

Hi everybody

 

as I'm trying to port some of my TCL cli-code to nexus, I am missing access to force the tty to raw mode in NX-OS 5.2. On IOS I was able to disable "cooked" mode by disabling enhanced editing (terminal no editing). Until NX-OS 4 I was able to open a pipe to a bash-shell and fire any command to manipulate the tty-device directly on the Linux-Level. But with release 5 this possibility was gone :-(

 

As a example the following tcl-script determines the current terminal-window size. It is working on IOS but on NX-OS you need to press ENTER to let NX-OS handle the input on stdin.

 

package require Tcl 8.3

# NOT working on a VTY but this is what we need
# fconfigure stdin -blocking 0 -encoding binary -buffering none

#########
# The UNIX-way
#########
# exec stty raw <@stdin
#########

#########
# Following is working on IOS but not available on NX-OS
#########
terminal international
terminal special-character-bits 8
terminal exec-character-bits 8
terminal no editing
#########

set terminal_response ""

# Jump to position 1023:1023 and ask for the cursor position
# It is at the last postion of the screen, so we know the size
# now
puts "\033\[1023;1023H\033\[6n\033\[3n"

# We need to flush the output, otherwise the cursor-position
# might not be already written to stdin
flush stdout

# We need to hurry up and do nothing else, otherwise
# cisco will destroy the buffer!
set character [read stdin 1]

while { $character != "R" } {
    append terminal_response $character
    set character [read stdin 1]
}

set code_point 0
set length [ string length terminal_response ]
set dimensions ""

for { set index 0 } { $index < $length } { incr index } {
    set character [ string index $terminal_response $index ]
    scan $character %c code_point
   
    if { ( $code_point >= 48 && $code_point <= 57 ) || ( $code_point == 59 ) } {
        append dimensions $character
    }
}

set splitted [ split $dimensions ";" ]
set __SCREEN_DIMENSIONS(height) [ lindex $splitted 0 ]
set __SCREEN_DIMENSIONS(width) [ lindex $splitted 1 ]

# Clear Screen and reset
puts "\033\[2J\033\[H"

puts "Terminal-Height: $__SCREEN_DIMENSIONS(height)"
puts "Terminal-Width: $__SCREEN_DIMENSIONS(width)"

 

Thanks in advance to anybody trying to help.

 

Regards

Sebastian

Outcomes