Create a tempfile without opening it in Ruby

前端 未结 4 2022
悲&欢浪女
悲&欢浪女 2021-01-04 21:11

Is there a way to create a tempfile, without having it opened? I have to run an executable, redirect it\'s output to a file, and then read & parse that. Everything creat

4条回答
  •  温柔的废话
    2021-01-04 21:32

    You can also use Dir::Tmpname

    Dir::Tmpname.create('your_application_prefix') { |path| puts path }
    

    path will contain unique path

    See https://github.com/ruby/ruby/blob/ruby_1_9_3/lib/tmpdir.rb#L116

提交回复
热议问题