From: Ben Giddings Date: 2009-09-11T00:08:38+09:00 Subject: Re: Ruby1.9 Encoding On Sep 10, 2009, at 09:39, Yukihiro Matsumoto wrote: > I had some difficulty to see your intention from the code. Could you > show us the exception messages you've got? My interpretation of the code is: def run(txt) # translate the string into EUC-KR encoding txt = txt.encode("EUC-KR") # Create a temp file to store the data and # write it to the file, using the EUC-KR encoding kts_file = Tempfile::new('kts_text') kts_file = open(kts_file.path, "w:EUC-KR") kts_file << "#{txt}\n" kts_file.close # Run ktspell, feeding it the data from the file cmd = "ktspell < #{kts_file.path}" # 2> /dev/null" # Read the result and translate it into UTF-8 IO::popen(cmd, "r:EUC-KR").read.encode("UTF-8") end I don't know much about 1.9's encodings, but can suggest a more rubyish way of writing the method: def run(txt) euc_txt = txt.encode("EUC-KR") # Tempfile::new actually returns a filehandle, so there's no need to re-open # the file based on the path. Since you seem to want to open the file, # write to it, use the data, and then immediately do away with the file, # the 'open' block form is probably more appropriate kts_file = Tempfile::open("kts_text") do |kts_file| # The more common way to write a newline-terminated string to a file is # file.puts(foo) rather than file << "#{foo}\n" kts_file.puts(euc_txt) cmd = "ktspell < #{kts_file.path}" # You could do all the rest on one line as you did, but this lets you # look at the data first using 'p processed_euc_txt' or something processed_euc_txt = IO::popen(cmd, "r:EUC-KR").read # Again, a temporary variable to let you see if the data looks right. processed_utf_txt = processed_euc_txt.encode("UTF-8") end processed_utf_txt end Ben