TCL read character from process output

  Kiến thức lập trình

I would like to read all the characters from a process output that doesnt output new line.

set process  [open "|program_flash" r ]
while {[gets $process line] >= 0} { puts $line}

Now the problem is like I said when lines with n are print I get the lines, but in my case it prints something like this.

Part    Start Sector    Num Sectors UUID        Type
  1 63          4208967     00000000-01 0c
Z> 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...fatwrite ssd 0:1 00000000 ssc.BIN

I would like to print all the percentage values that are later used in another script.
The above line is only printed once it prints till the end.
Much appreciated

6

So the solutions is simple:

while {1} {
    set c [read $process 1]
    puts -nonewline "$c"
    flush stdout
    if {[eof $process]} {
            break
    }
}

Like this is going to print all characters(even when there is no CR/new line) until eof

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT