From: Hidetoshi NAGAI Date: 2006-11-27T11:05:20+09:00 Subject: Re: Truncating string set on $0 From: "Joao Pedrosa" Subject: Truncating string set on $0 Date: Mon, 27 Nov 2006 09:36:51 +0900 Message-ID: > To make it work transparently, I used to set the $0 variable to > the filename of the second script, and everything, for months, > ran smoothly. That is, until today. Today I noticed that a large > filename string could be truncated, and it seems that the length > depends on the initial command for launching Ruby. I got same problem on Ruby/TkORCA. Based on advice on ruby-dev ML, I wrote the following for a script on a sandbox. If you don't need the full string on 'ps' command, you'll be able to avoid the problem by similar way. ---------------------------------------------------------------------- # # replace_progname_globalvar.rb # # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # ########################################### # replace $0 and $PROGRAM_NAME ########################################### progname_obj = Object.new progname_obj.instance_variable_set(:@progname_tbl, Hash.new('tkorca'.freeze)) class << progname_obj def __set_progname_for_ip__(name, ip) TkORCA.security_check(5) if MultiTkIp.__getip != ip @progname_tbl[ip] = name.to_s end def __set_progname__(name) @progname_tbl[MultiTkIp.__getip] = name.to_s end def to_str @progname_tbl[MultiTkIp.__getip] end alias to_s to_str alias inspect to_str def ===(other) other === self.to_str end def ==(other) other == self.to_str end def equal?(other) other.equal?(self.to_str) end def eql?(other) other.eql?(self.to_str) end def method_missing(id, *args) self.to_str.__send__(id, *args) end end progname_obj.__set_progname__($0) $program_name = progname_obj alias $REAL_PROGRAM_NAME $0 alias $PROGRAM_NAME $program_name alias $0 $program_name trace_var(:$program_name){|val| unless progname_obj.object_id == val.object_id program_obj.__set_progname__(val) $program_name = progname_obj end } ---------------------------------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)