Question

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'"

}
Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top