tags:

views:

176

answers:

2

I'm trying to find out if Ruby has en equivalent of php's fopen() method currently used like this:

$fd = fopen("php://stdin", "r");

would that be using ARGV variable?

Basically what I plan on doing is forward raw e-mail messages using the .procmailrc file which I already got working in a test php file, but the project requires the use of Ruby. Therefore I'm not 100% sure if using the ARGV variable would work or if somehow I need to capture the e-mail stream by some other means.

Any help would be greatly appreciated. Thanks :)

+2  A: 

ARGV and the (standard) input stream are two different things. ARGV contains the parameters passed to an executable, like someapp a b c where a, b and are parameters. stdin is a file handle. You usually have three standard streams. stdin which is read-only, stdout and stderr which are write-only.

In Ruby you can use the predefined constants STDIN, STDOUT and STDERR to access the default streams. There are also the variables $stdin, $stdout, $stderr which are initialized with the same values as STDIN, STDOOUT and STERR but may be re-assigned other values.

VolkerK
A: 

You were probably referring to ARGF variable, have a look:

http://stackoverflow.com/questions/273262/best-practices-with-stdin-in-ruby/273841#273841

Mladen Jablanović