[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Having Ruby 1.8 decide on "File.open" or 'IO.popen'?

Josef 'Jupp' Schugt

11/20/2004 10:41:00 PM

Hi!

To write to (mbox) file I use "File.open('/var/spool/mail/jupp')". To
write to a (MDA) stream I would use "File.popen('/usr/bin/fetchmail')".
Is there an *existing* means that I can use for both purposes so that I
can code as follows?

SomeClass.open('/var/spool/mail/jupp')
SomeClass.open('| /usr/bin/fetchmail')

Or is there good reason *not* to do that?

Josef 'Jupp' Schugt
--
Messages larger than 100 KiB will be discarded *without* notification!
http://oss.erdfunkstell... German ed. of comp.lang.ruby FAQ



3 Answers

Neil Stevens

11/20/2004 11:33:00 PM

0

On Sun, 21 Nov 2004 07:41:04 +0900, Josef 'Jupp' Schugt wrote:

> Hi!
>
> To write to (mbox) file I use "File.open('/var/spool/mail/jupp')". To
> write to a (MDA) stream I would use "File.popen('/usr/bin/fetchmail')".
> Is there an *existing* means that I can use for both purposes so that I
> can code as follows?
>
> SomeClass.open('/var/spool/mail/jupp')
> SomeClass.open('| /usr/bin/fetchmail')
>
> Or is there good reason *not* to do that?

"| " are valid characters to start a filename, so how would you
distinguish what is intended?

--
Neil Stevens - neil@hakubi.us
"The world is a dangerous place to live; not because of the people who
are evil, but because of the people who don't do anything about it."
-- Albert Einstein(?)

David G. Andersen

11/21/2004 3:14:00 AM

0

On Sun, Nov 21, 2004 at 07:41:04AM +0900, Josef 'Jupp' Schugt scribed:
> Hi!
>
> To write to (mbox) file I use "File.open('/var/spool/mail/jupp')". To
> write to a (MDA) stream I would use "File.popen('/usr/bin/fetchmail')".
> Is there an *existing* means that I can use for both purposes so that I
> can code as follows?
>
> SomeClass.open('/var/spool/mail/jupp')
> SomeClass.open('| /usr/bin/fetchmail')

Kernel.open("/var/spool/mail/jupp")
Kernel.open("| /usr/bin/fetchmail")

> Or is there good reason *not* to do that?

If there's any user-supplied data in the string and you want to
be certain you're opening a file. From a security standpoint,
File.open is better because it cannot spawn a sub-shell or invoke
other programs. This only matters in certain contexts, obviously.

-Dave

--
work: dga@lcs.mit.edu me: dga@pobox.com
MIT Laboratory for Computer Science http://www....


Josef 'Jupp' Schugt

11/22/2004 9:23:00 PM

0

Neil Stevens wrote:
> On Sun, 21 Nov 2004 07:41:04 +0900, Josef 'Jupp' Schugt wrote:
>>
>>SomeClass.open('/var/spool/mail/jupp')
>>SomeClass.open('| /usr/bin/fetchmail')
>>
>>Or is there good reason *not* to do that?
>
>
> "| " are valid characters to start a filename, so how would you
> distinguish what is intended?

By means of quoting:

SomeClass.open('| /usr/bin/fetchmail') # Stream
SomeClass.open('\|\ /usr/bin/fetchmail') # File

Josef 'Jupp' Schugt
--
Messages larger than 100 KiB will be discarded *without* notification!
http://oss.erdfunkstell... German ed. of comp.lang.ruby FAQ