我正在尝试使用 Open3 将地图内容写入 csv 文件。这是正在使用的代码
def run_command(command,exit_on_error=false,error_msg='')
if command.nil? || command.empty?
return nil
end
exit_status=0
output=[]
error=[]
Open3.popen2e(command) do |stdin, stdout_and_stderr, wait_thr|
pid = wait_thr.pid # pid of the started process.
stdout_and_stderr.each do |line|
puts line
output=output+[line]
end
exit_status = wait_thr.value
end
unless error.empty?
end
if exit_on_error && exit_status.exitstatus !=0
exit exit_status.exitstatus
end
return {:returncode=>exit_status.exitstatus,:output=>output.map{|ln| ln.chomp}}
end
地图创建逻辑如下
while (file = queue.deq)
begin
cat = 'cat'
if file.split('.').last=='gz' || file.split('.').last=='zip'
cat = 'zcat'
end
user_ids.each do |user|
res = run_command("aws s3 cp #{file} - | #{cat} | grep #{user} | wc -l",true,'s3cmd stream failed')
output = "#{user},#{file.split('/')[-1]},#{file.split('/')[-2]},#{res[:output][0]}"
if "ab".eql?(file.split('/')[-2])
data_source ="ab"
elsif "cde".eql?(file.split('/')[-2])
data_source ="cde"
elsif "fgh".eql?(file.split('/')[-2])
data_source ="fgh"
elsif "jik".eql?(file.split('/')[-2])
data_source ="jik"
else
data_source ="NA"
end
end
end
end
是否可以将地图对象写入 csv 文件?这里有什么错误。我没有任何红宝石的基础知识。期待快速重播
注意:我可以将字符串内容写入 csv