Skip to content

Instantly share code, notes, and snippets.

@tamouse
Last active December 19, 2015 13:40
Show Gist options
  • Save tamouse/5964037 to your computer and use it in GitHub Desktop.
Save tamouse/5964037 to your computer and use it in GitHub Desktop.
running csv output through popen
$ irb -r open3 -r csv
2.0.0-p247 :001 > Open3.popen2e("cat > blah") do |i,oe,t|
2.0.0-p247 :002 > csv = CSV.new(i)
2.0.0-p247 :003?> csv << [1,2,3,4]
2.0.0-p247 :004?> csv.close
2.0.0-p247 :005?> end
=> nil
2.0.0-p247 :006 > quit
tamara@pontiki:~/Dropbox/Public/Examples:2013-07-10@12:00:08
$ file blah
blah: ASCII text
tamara@pontiki:~/Dropbox/Public/Examples:2013-07-10@12:00:12
$ more blah
1,2,3,4
2.0.0-p247 :001 > Open3.popen2e("cat > blah") do |i,oe,t|
2.0.0-p247 :002 > CSV(i) do |csv|
2.0.0-p247 :003 > csv << [1,2,3,4,'five']
2.0.0-p247 :004?> end
2.0.0-p247 :005?> end
=> <#CSV io_type:IO encoding:UTF-8 lineno:1 col_sep:"," row_sep:"\n" quote_char:"\"">
2.0.0-p247 :006 > quit
tamara@pontiki:~/Dropbox/Public/Examples:2013-07-10@12:15:12
$ file blah
blah: ASCII text
tamara@pontiki:~/Dropbox/Public/Examples:2013-07-10@12:15:17
$ cat blah
1,2,3,4,five
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment