Two problems:
1.) I can't seem to ever get the eof value to be 1...it's
always 0 (i.e. - not eof)!
set fid [open "| c_prgm" "r+"]
fconfigure $fid -buffering line
fconfigure $fid -blocking no
fileevent $fid readable "get-data $fid"
.
.
.
proc get_data {fid} {
while {![eof $fid]} {
set line [read $fid]
}
set first_elem [lindex $line 0]
set last_elem [lindex $fid end]
}
2.) When I only use one fflush(stdout)
cmd in the c_prgm, I get the correct "first_elem" (i.e. START) and "last_elem" (i.e. END). When I use the fflush after each fprintf, I don't get the right results. I played around with the -fconfigure buffering value (auto, none), but it seems that the solution is to NOT to do multiple fflush's. Although I got it to work for small data output coming from the c_prgm, I'm concerned when I start outputting large amounts of data from the c_prgm. My goal though is always the same: I want to have access to the first and last value of any output from the c_prgm, regardless of the size of output.
example of c_prgm:
fprintf(stdout, "START\n"
fprintf(stdout, "A\n"
fprintf(stdout, "B\n"
fprintf(stdout, "C\n"
fprintf(stdout, "END\n"
fflush(stdout);
Can someone elaborate on this whole phenonmina with buffering, eof, read cmd, and gets cmd. Thanks!!!
1.) I can't seem to ever get the eof value to be 1...it's
always 0 (i.e. - not eof)!
set fid [open "| c_prgm" "r+"]
fconfigure $fid -buffering line
fconfigure $fid -blocking no
fileevent $fid readable "get-data $fid"
.
.
.
proc get_data {fid} {
while {![eof $fid]} {
set line [read $fid]
}
set first_elem [lindex $line 0]
set last_elem [lindex $fid end]
}
2.) When I only use one fflush(stdout)
cmd in the c_prgm, I get the correct "first_elem" (i.e. START) and "last_elem" (i.e. END). When I use the fflush after each fprintf, I don't get the right results. I played around with the -fconfigure buffering value (auto, none), but it seems that the solution is to NOT to do multiple fflush's. Although I got it to work for small data output coming from the c_prgm, I'm concerned when I start outputting large amounts of data from the c_prgm. My goal though is always the same: I want to have access to the first and last value of any output from the c_prgm, regardless of the size of output.
example of c_prgm:
fprintf(stdout, "START\n"
fprintf(stdout, "A\n"
fprintf(stdout, "B\n"
fprintf(stdout, "C\n"
fprintf(stdout, "END\n"
fflush(stdout);
Can someone elaborate on this whole phenonmina with buffering, eof, read cmd, and gets cmd. Thanks!!!