Create a tempfile without opening it in Ruby
问题 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 created by tempfile is already opened, and this triggers an error , because the file is locked. 回答1: Is using FileUtils.touch acceptable solution? You can touch a file and delete it once you are done with whatever you want. 回答2: You can also use Dir::Tmpname Dir::Tmpname.create('your_application_prefix') { |path| puts path } path