pretty print to a file in ruby

后端 未结 7 775
甜味超标
甜味超标 2021-02-07 00:11

I am trying to pretty print a hash to a file.

I tried unix redirects [added different flags to it incrementally] :

`echo #{pp  mymap} | tee summary.out          


        
7条回答
  •  生来不讨喜
    2021-02-07 00:30

    Doing something similar to what Edu suggested and How do I redirect stderr and stdout to file for a Ruby script? helped.

    Here is how the new code is similar to:

    $stdout.reopen(@dir_+"/my_file.out",'w+')
    puts "All metrics are:"
    pp final_map
    $stdout=STDOUT
    

    Would still be interested to know why redirection operators > , and 2>&1 in back-ticks doesn't work

提交回复
热议问题