質問

I am using "pipe to program" option in Evolution email client, that runs following ruby script

#!/usr/bin/ruby
%% example code below
junk_mail = 2
junk_mail

Now this program always returns 0, irrespective of what the value of junk_mail variable is.

I guess it has something to do with Evolution forking a child process to run this code, and always 0 (clean exit) is received back?

Help needed.

EDIT

I figured out actual problem is with data being read from pipe. Following code works fine when tested in command line, but it is unable to read pipe data when called from Evolution client

#!/usr/bin/ruby
email_txt = ARGF.read
File.open("~/debug.txt", 'a') { |file| file.write(email_txt + "\n") }


$cat email.txt | ./myprog.rb

This gives debug.txt as expected, but when called from Evolution pipe-to-program, it gives empty data.

Am I using the correct way to read piped stream data when called from external program? (I am under Fedora 20).

役に立ちましたか?

解決

Use exit:

#!/usr/bin/ruby

junk_mail = 2
exit junk_mail

You can test this by running it from the command line in linux, then echoing the exit value via

echo $?

EDIT

To read STDIN into a single string:

email_txt = STDIN.readlines.join
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top