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.
In any case, all arguments ( basename , tmpdir , mode , and **options ) will be treated as ::new. Creates a temporary file with permissions 0600 (= only readable and writable by the owner) and opens it with mode “w+”. The temporary file will be placed in the directory as specified by the tmpdir parameter.
Rewind resets the line number to zero f = File.new("testfile") f.readline #=> "This is line one\n" f.rewind #=> 0 f.lineno #=> 0 f.readline #=> "This is line one\n" IO#close. Closes ios and flushes any pending writes to the operating system. read([length [, outbuf]]) Reads length bytes from the I/O stream.
A TMP file refers to a transitory backup, storage, or other file system generated by a software program. It is occasionally created as an invisible file and is frequently destroyed when the program is quit. TMP files can also be used to temporarily store information while a new file is being constructed.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With