문제

I am writing a small expect(TCL) script to send a series of numbers in hex format and expect something. I am iterating over a loop to send the bytes one by one. but I am not able to send the number in hex form.

Below is a sample code. I need to send the first line over a loop with numbers in 0x form. second line is something I tried out.

send "show hardware internal qengine inst 0 memory ib_rr0_span_dc3hdr start 0x0 num 0x2 \r"
expect "#"

for {set i 0} {$i < 16} {incr i 1} {
puts stdout "i val: $i '\x$i'"

}
도움이 되었습니까?

해결책

Long time since I did TCL but I believe the following will do what you want

puts stdout [format "i val %d '\x%x'" $i $i] 

The %d and %x placeholders are almost the same as you would find in a C printf/sprintf statement and allow such things as leading zeros, field sizes etc

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top