How to feed data over STDIN to multiple external commands in ruby.

Posted by Erik on Stack Overflow See other posts from Stack Overflow or by Erik
Published on 2011-01-14T10:42:12Z Indexed on 2011/01/14 10:53 UTC
Read the original article Hit count: 286

Filed under:
|
|
|
|

This question is a bit like my previous (answered) question:

How to run multiple external commands in the background in ruby.

But, in this case I am looking for a way to feed ruby strings over STDIN to external processes, something like this (the code below is not valid but illustrates my goal):

#!/usr/bin/ruby

str1 = 'In reality a relatively large string.....'
str2 = 'Another large string'
str3 = 'etc..'

spawn 'some_command.sh', :stdin => str1
spawn 'some_command.sh', :stdin => str2
spawn 'some_command.sh', :stdin => str3

Process.waitall

© Stack Overflow or respective owner

Related posts about ruby

Related posts about shell