创建一个临时文件而不在 Ruby 中打开它 [英] Create a tempfile without opening it in Ruby

查看:36
本文介绍了创建一个临时文件而不在 Ruby 中打开它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在不打开临时文件的情况下创建它?我必须运行一个可执行文件,将它的输出重定向到一个文件,然后读取 &解析那个.tempfile 创建的所有内容都已打开,这会触发错误,因为文件已锁定.

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.

推荐答案

正在使用 FileUtils.触摸可接受的解决方案?您可以触摸文件并在完成任何您想要的操作后将其删除.

Is using FileUtils.touch acceptable solution? You can touch a file and delete it once you are done with whatever you want.

这篇关于创建一个临时文件而不在 Ruby 中打开它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆