A small routine to print a given file under Windows (note it blows up if the extension is not registered or if there is no print command for the extension -- feel free to add error checking).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | proc WindowsPrintFile {fileName} {
package require csv
##
## Get the print command for this type
##
set ext [file extension $fileName]
set app [registry get [format {HKEY_CLASSES_ROOT\%s} $ext] {}]
set app [format {HKEY_CLASSES_ROOT\%s\shell\print\command} $app]
set cmdList {}
foreach cmdElement [::csv::split [registry get $app {}] { }] {
lappend cmdList [string map {%1 %1$s} $cmdElement]
}
##
## Print the file -- catch is needed because return codes are not Unix ones!!!
##
set cmd [format $cmdList $fileName]
catch {eval exec $cmd} msg
##
## All done, so return
##
return;
}
|
Tags: platform