Ruby script to read output from alias

I have an alias in /etc/aliases

, so every time an email arrives at a specific address, the body of the email is sent to a Ruby script. For instance:

example: |/etc/smrsh/my_script.rb

I need to know how to read pipe data in my Ruby script. I wrote a simple Perl script that can read data. I just can't figure out how to do this in Ruby.

Here are the relevant lines in the Perl script:

my $fout = "/tmp/email.out";

open( EM, ">$fout" );

while( <> )  {
    chomp;
    print EM "$_\n";
}

      

0


a source to share


1 answer


You can use STDIN

to read your data. The equivalent of your Perl code would be something like this:



out = File.open("/tmp/email.out", "a+")
STDIN.each do |line|
  out.puts line
end

      

+3


a source







All Articles