2017-02-14 53 views
0

我在爲Puppet寫一個事實。UTF-8 Ruby中的無效字節序列

我有一個用戶名array = ["user1", "user2", "user3"]數組,然後一個代碼

array.each do |item| 
    temp_data << Facter::Core::Execution.exec("net user #{item} /DOMAIN") 
end 
search_text = %r{comment|Local} 
users_data = [] 
temp_data.each do |line| 
    line.each_line do |num| 
    users_data << (num) unless num =~ search_text 
    end 
end 

TEMP_DATA產生很好,但我得到一個錯誤錯誤puppetlabs.facter - 錯誤而定製的解決實際上是「winusers_domain」:無效字節序列UTF-8,但它不顯示女巫線的錯誤是。任何建議?

回答

0

我已經想通了,所以我回答自己。

array.each do |item| 
    temp_data << Facter::Core::Execution.exec("net user #{item} /DOMAIN") 
end 
search_text = %r{comment|Local} 
users_data = [] 
temp_data.each do |line| 
    line.encode!('UTF-16', 'UTF-8', :invalid => :replace, :replace => '') 
    line.encode!('UTF-8', 'UTF-16') 
    line.each_line do |num| 
    users_data << (num) unless num =~ search_text 
    end 
end 
相關問題