what's the differences between IO.popen ( or IO.pipe) andPTY.spawn??

J

Jun Young Kim

Hi, all.

The program I want to execute as a external program in ruby is using a
write system call.

When I use IO.popen or IO.pipe, there is no output because of the
external program didn't flush it's output. (but, when I executed it in
shell, normally it shows up outputs).

But, when I use PTY.spawn(), the output is generated.

what's the differences between them??
 
J

James Gray

The program I want to execute as a external program in ruby is using
a write system call.

When I use IO.popen or IO.pipe, there is no output because of the
external program didn't flush it's output. (but, when I executed it
in shell, normally it shows up outputs).

Try doing it this way:

output = IO.popen("command here", "w+") { |cmd|
cmd.close_write
cmd.read
}

A lot of times, closing the writing stream will trigger the output.
Hope that helps.

James Edward Gray II
 
J

Jun Young Kim

Actually, I didn't work normally for my case.

after getting a read io pipe, my program is waiting some events by =20
using select.

but it always returns nil because the external program did =20
nothing(didn't flush something)

thanks for response.

2009. 04. 20, =BF=C0=C0=FC 11:43, James Gray =C0=DB=BC=BA:
 
R

Robert Klemme

2009/4/20 Jun Young Kim said:
Actually, I didn't work normally for my case.

after getting a read io pipe, my program is waiting some events by using
select.

but it always returns nil because the external program did nothing(didn't
flush something)

thanks for response.

As I said in my previous posting many programs ensure complete lines
are sent to the output channel if it is a terminal but they do not if
the output is a file or pipe because it is assumed that there
immediate delivery does not matter and hence not flushing individual
lines yields more throughput.

Cheers

robert
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top