Hello all,
I am implementing modules at my site and am using the
stable 3.1.6 version.
I wrote a module for helping users to select a default
printer. I tested it using the tcl interpreter and in
that environment, it works as expected.
When I run it as a module or unload it, it works as
expected. The problem arrises when I try run 'module
update'. I get the following error.
:>module update printers
printers(74):ERROR:102: Tcl command execution failed:
if [file exists /home/kpatton/.printer] {
set printerFile [open ~/.printer r];
gets $printerFile printer;
close $printerFile;
} else {
#Get a list of printers that are currently up
GetPrinters;
set returnStatus [ChoosePrinter {x}];
while { $returnStatus == 0 } {
puts stderr "Please choose your default printer"
gets stdin printer;
set returnStatus [ChoosePrinter "$printer"];
}
}
I was wondering if anyone had any suggestions on what
the issue is and how I could resolve it?
Here is the complete module
#%Module1.0#####################################################################
#!/usr/bin/tcl
##
## modules modulefile
##
proc ModulesHelp { } {
global version modroot
puts stderr "\tChoose your default printer for
a list\n";
puts stderr "\tPrinter is saved to the file
~/.printer";
}
module-whatis "Provides list of printer from which
you may select a default\n";
proc GetPrinters {} {
global arr;
set command {lpq -a};
set lines [open "|$command" r];
foreach line [split [read $lines] \n] {
#Skip lines that do not have a '@'
if [regexp {^Printer: (.*)@.*auto; ([\w\s]+)}
$line match bingo msg] {
} elseif [regexp {^Printer: (.*)@.*} $line
match bingo] {
set msg "unavailable or location unknown";
}
set arr($bingo) $msg;
}
}
proc ChoosePrinter {printer} {
#Test if the printer passed is valid
global arr;
if [info exists arr($printer)] {
#It is o.k. to write the prefered printer file
puts stderr "Saved selection to ~/.printer";
puts stderr "To reset your default printer and
get this menu again,"
puts stderr "delete the file and run 'module load
printer'"
set printerFile [open ~/.printer w];
puts $printerFile $printer;
return 1;
} else {
#Try again
set returnStatus [string compare $printer "x"] ;
if {$returnStatus != 0} {
#Don't print the 'No such printer error'
puts stderr "No such printer, try again";
}
#Print out the list of available printers
foreach index [array names arr] {
set choice [format "%-16s %s" $index
$arr($index)];
puts stderr $choice;
}
}
return 0;
}
setenv PRINTER printer
#Load the default printer if it already exists
if [file exists /home/kpatton/.printer] {
set printerFile [open ~/.printer r];
gets $printerFile printer;
close $printerFile;
} else {
#Get a list of printers that are currently up
GetPrinters;
set returnStatus [ChoosePrinter {x}];
while { $returnStatus == 0 } {
puts stderr "Please choose your default printer"
gets stdin printer;
set returnStatus [ChoosePrinter "$printer"];
}
}
I saw a reference to the ERROR:102 in the PROBLEMS
file
that is included in the distribution. I do have a
blank line at the end of the script. The problem I
have described happens under both Linux and Solaris.
Thanks,
Kirk
|