From: Caleb Clausen Date: 2010-07-06T22:30:13+09:00 Subject: Re: editing text using $EDITOR from program On 7/6/10, R.. Kumar 1.9.1 OSX wrote: > R.. Kumar 1.9.1 OSX wrote: > >> >> However, since "mail -s" requires both input, as well as some command >> line parameters (title and emailid), i was not clear whether this method >> would work. >> >> thx. > > This works: > > def pipe_output (str) > > pipeto = %q{mail -s "a title" myemail } > if pipeto != nil # i was taking pipeto from a hash, so checking > proc = IO.popen(pipeto, "w+") > proc.puts str > proc.close_write > #puts proc.gets > end > end > > str = "this is some data to go in mail" > pipe_output str > > Not sure which is cleaner and more reliable though, this way or: > > cmd = %q{cat file.txt | mail -s "title" email} > system(cmd) Either way should work fine, but I would go with popen, personally. I think it's a little cleaner semantically; might be a tad more portable too.