2004-8-28 SRIV I use this code to print to a lpr printer from my tcl based text editor.
proc lprprint { filename {hostname "localhost"} {queuename "lp"}} {
set filehndl [open $filename r]
fconfigure $filehndl -translation binary
set printdata "[read $filehndl]"
close $filehndl
set n [string range [clock seconds] end-2 end]
set size [string length $printdata]
set c "HSYSM\n"
append c "PSAF0006\n"
append c "fdfA${n}SYSM\n"
append c "UdfA${n}SYSM\n"
append c "NDEFSYSM.SAF0006.SAF00066.JOB07513.D0000103.?\n"
set clen [format %04d [string length $c]]
set ca "\x02${queuename}\n"
set cb "\x02${clen} cfA${n}SYSM\n"
set da "\x03${size} dfA${n}SYSM\n"
set safety [after 10000 {return}]
set sockhandl [socket $hostname 515]
fconfigure $sockhandl -translation binary
puts -nonewline $sockhandl $ca
flush $sockhandl
set x [read $sockhandl 1]
puts -nonewline $sockhandl $cb
flush $sockhandl
set x [read $sockhandl 1]
puts -nonewline $sockhandl "$c\x00"
flush $sockhandl
set x [read $sockhandl 1]
puts -nonewline $sockhandl "$da"
flush $sockhandl
set x [read $sockhandl 1]
puts -nonewline $sockhandl "$printdata\x00"
flush $sockhandl
close $sockhandl
after cancel $safety
}