0

In Python3, I have this code:

arg, unk = parser.parse_known_args()
buf = ''

for line in fileinput.input(unk):
    buf += line
fileinput.close()

This code allows me to get piped data along with arguments to the program.

What I am achieving is to get piped e-mail from postfix. Postfix pipe email file to my python app and also add some arguments that I want. In Ruby I cannot find a proper way of doing this. Piped data can be max. ~25MB. So I need a correct, proper and smooth way of handling this. I want to handle even large files without issues.

ruby test.rb --option ARG

Of course, I can get arguments easily but I also want to get PIPED data.

In fact, I cannot find exact method that Ruby has for getting piped data. I am stuck at this point. Can anyone give me a hand on this?

Dennis
  • 1,805
  • 3
  • 22
  • 41
  • 1
    God sake, I searched many terms. ARGF? I just learned this now and yes, This is what I want. In fact more than what I want. I found many useful methods that I can implement for myself. Thanks. --Maybe add as an answer? **Also** thanks to you now, I found a simple sample. Maybe useful for others: http://stackoverflow.com/questions/273262/best-practices-with-stdin-in-ruby – Dennis May 08 '17 at 12:38
  • Yep, great find! – Sergio Tulentsev May 08 '17 at 12:41

1 Answers1

2

It seems that in ruby you want to read from ARGF. It handles files passed as filenames or piped to your program.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367