Prev: Increase significant digits in Float
Next: Training
From: Albert Schlef on 2 Mar 2010 21:19 I'm writing a program that needs to generate two or three temporary files. (Specifically: my program runs a shell command and I need to pass the shell command a path to a non-existing file which it will dump data to.) Is there a 'gem' that manages these things? Preferably it should remove the files when the script finishes or whatever. Of course, if Ruby supports this built-in that's fine too (I did 'ri File' and 'ri FileUtils' but founds nothing). -- Posted via http://www.ruby-forum.com/.
From: Paul Harrington on 2 Mar 2010 21:25 Albert Schlef wrote: > I'm writing a program that needs to generate two or three temporary > files. > > (Specifically: my program runs a shell command and I need to pass the > shell command a path to a non-existing file which it will dump data to.) > > Is there a 'gem' that manages these things? Preferably it should remove > the files when the script finishes or whatever. > > Of course, if Ruby supports this built-in that's fine too (I did 'ri > File' and 'ri FileUtils' but founds nothing). ri Tempfile that'll get you started -- Posted via http://www.ruby-forum.com/.
From: Albert Schlef on 2 Mar 2010 23:07 Paul Harrington wrote: > Albert Schlef wrote: >> I'm writing a program that needs to generate two or three temporary >> files. >> >> (Specifically: my program runs a shell command and I need to pass the >> shell command a path to a non-existing file which it will dump data to.) [...] > ri Tempfile > > that'll get you started Thanks! I didn't know about Tempfile. Though I have a little problem: Tempfile let me *open* a new temporary file. But I just need to generate a temporary file *name*, which I'll pass to a shell command. I guess I'll immediately close the handle Tempfile.new() returns and pass its path() to the shell command. -- Posted via http://www.ruby-forum.com/.
From: Robert Klemme on 3 Mar 2010 02:07 On 03/03/2010 05:07 AM, Albert Schlef wrote: > Paul Harrington wrote: >> Albert Schlef wrote: >>> I'm writing a program that needs to generate two or three temporary >>> files. >>> >>> (Specifically: my program runs a shell command and I need to pass the >>> shell command a path to a non-existing file which it will dump data to.) > [...] >> ri Tempfile >> >> that'll get you started > > Thanks! I didn't know about Tempfile. > > Though I have a little problem: Tempfile let me *open* a new temporary > file. But I just need to generate a temporary file *name*, which I'll > pass to a shell command. You could use a dirty hack and abuse a private method: irb(main):005:0> Tempfile.open('/tmp') {|tf| p tf, tf.send(:make_tmpname,'a','o')} #<File:/tmp/tmp20100303-4173-rdy9aq-0> "a20100303-4173-kvk0d3-o" => [#<File:/tmp/tmp20100303-4173-rdy9aq-0 (closed)>, "a20100303-4173-kvk0d3-o"] irb(main):006:0> > I guess I'll immediately close the handle Tempfile.new() returns and > pass its path() to the shell command. What do you want the external program to do with the tempfile? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
From: botp on 3 Mar 2010 02:28
On Wed, Mar 3, 2010 at 10:19 AM, Albert Schlef <albertschlef(a)gmail.com> wrote: > I'm writing a program that needs to generate two or three temporary > files. > > (Specifically: my program runs a shell command and I need to pass the > shell command a path to a non-existing file which it will dump data to.) man mktemp man tempfile > Is there a 'gem' that manages these things? Preferably it should remove > the files when the script finishes or whatever. it is builtin in ruby. but in this case, you'd better do it all in ruby... best regards -botp |