This is a less severe counterpart of Help! My Tcl application just crashed!.
[Fill in useful general advice.]
Questions and Answers
2005/1/11 BM - file open / read problem
What am I doing wrong here? The following code works in Linux, but under win98 the wm title is updated with "/" as the separator and the application then freezes requiring a 3 finger salute to kill it. $fidd is a full pathname of a jpg file, the 1st read dumps 6 bytes, the second reads the file type (JFIF of EXIF) which is then displayed in the label .type
wm title . "File = $fidd" set fid [open $fidd r] set type [read $fid 6] set type [read $fid 4] close $fid .type conf -text $type
Any ideas please.
Peter Newman 11 January 2005: The "/" if the filename is correct; because Tcl always uses "/" as the file separator, even on Windows. To get backslashes use:-
wm title . "File = [file nativename $fidd]"
The rest of the code looks OK to me. I assume you created the widget?:-
label .type
Does it work if you comment out the open/read/close - and replace it with say:-
set type "Hello World!"
Presumably read is blocking for some reason. Have you been fiddling with fconfigure? Or maybe it's the data in the file? Windows treats 1 ASCII character as an EOF character. And you can open files in binary or text mode. So if it's text mode - and you get the EOF character in the data - then presumably read will hang - because it waiting forever for the 4 or 6 bytes. That's consistent with it working on Linux but not Windows. Sorry, I can't recall the exact details of all this. It's documented somewhere, but I can't remember where.
13/01/2005 BM thanks for the reply. The code above checked out ok. The problem has been traced to the read command following:
set tst [read $fid 2 } binary scan $tst S* jump .ed2 insert end "jump = $jump" #display the decimal value of jump
In linux the code works fine, in windows the read returns an empty string if the characters read are outside the printable range.
The file has been opened r and encoding set to binary.
Can you help on this one please.
Peter Newman 13 January 2005: That closing brace on the first line is a Wiki page only typo I assume?
B M 13/1/04: Yes it should be ]. what I am doing is scanning a jpeg file for tags. The app crashes sometimes after finding the Exif tag FF E1. The 2 bytes being read are the length of the exif data which in some instances is not processed.
2 instances where it fails are when it reads in \x1A \x55, and \x1A \x5A while \x1D \x83 is processed correctly
Peter Newman 13 January 2005: Hex 1A is the nasty EOF char that causes problems in Windows. From the fconfigure manpage it looks to me like you have to set:-
-encoding binary -translation binary -eofchar {}
BM 14/1/2005 Thanks Peter,that solved the problem