IO with external program

D

Danny Beaudoin

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!
 
N

nobu.nokada

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top