Am trying to write map content to a csv file using Open3.This is the code am using
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
Map creation logic is given below
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
Is it possible to write map object to a csv file? what was the mistake here. I don't have any basic for ruby. Expecting a quick replay
Note:I can able to write a string content to csv