I have a little wrapper around TclTkIp to do tcl interpreting with a ruby program. It's super useful and has worked great -- until 1.8.2.
Now, it appears that calling the 'exit' command in tcl with an argument raises an exception for some reason. You can call 'exit', just not 'exit 0' or 'exit 1'.
Has something changed that makes this the desired behavior, or is this a bug? The tcltk that was built against handles 'exit 0' just fine.
Here are the details:
#!/usr/bin/env ruby
require 'tcltklib'
···
###
# The TclInterp class wraps up a few useful calls to the tcl interp
###########################################################################
class TclInterp
class TclError < RuntimeError
end
######## I N S T A N C E M E T H O D S ########
def initialize(name = 'default')
@interp = TclTkIp.new(name, nil) #nil disables tk
end
def get(varname)
val = self.raw_get(varname)
return val
end
def set(varname, val)
val = self.eval("set #{varname} #{val}")
return val
end
def eval(str)
begin
val = @interp._eval(str)
rescue => exc
raise TclError, exc.message + "\n" + self.get('errorInfo')
end
return val
end
def source(filename)
return self.eval("source #{filename}")
end
def raw_get(varname)
val = @interp._eval("set __ruby_dummy_var $#{varname}")
@interp._eval("unset __ruby_dummy_var")
return val
end
end
interp = TclInterp.new
interp.eval("exit 0")
Both of these are compiled against tcltk 8.3, linux/i386 (RHEL).
In Ruby 1.8.1:
darkshore:/tmp> ruby -v
ruby 1.8.1 (2003-12-25) [i386-linux]
darkshore:/tmp> ruby t.rb
darkshore:/tmp> echo $?
0
This works as expected. However, with Ruby 1.8.2, this fails (even though the interpreter works for everything else I can find):
darkshore:/tmp> ruby -v
ruby 1.8.2 (2004-12-25) [i386-linux]
darkshore:/tmp> ruby t.rb
t.rb:32:in `eval': (TclInterp::TclError)
while executing
"exit 0" from t.rb:49
darkshore:/tmp> echo $?
1