[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

IO with external program

Danny Beaudoin

5/28/2005 9:14:00 PM

Hi!
I would like to run a program from ruby and be able to give it its input and
receive the output. This program usually uses stdin and stdout. How may I
achieve this?
Thanks!




1 Answer

nobu.nokada

5/29/2005 4:50:00 AM

0

Hi,

At Sun, 29 May 2005 06:14:04 +0900,
Danny Beaudoin wrote in [ruby-talk:143900]:
> I would like to run a program from ruby and be able to give it its input and
> receive the output. This program usually uses stdin and stdout. How may I
> achieve this?

cmd = IO.popen("program arg1 arg2", "r+")
cmd.puts(data)
cmd.close_write
result = cmd.read

close_write might be unnecessary depending on the program, if it
doesn't wait EOF of stdin.

--
Nobu Nakada