Welcome, guest | Sign In | My Account | Store | Cart

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).

Tcl, 26 lines
 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;

 }
Created by Gerald Lester on Wed, 19 May 2004 (MIT)
Tcl recipes (162)
Gerald Lester's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks