[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

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

? ??

4/20/2009 2:18:00 AM

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??

3 Answers

James Gray

4/20/2009 2:43:00 AM

0

On Apr 19, 2009, at 9:17 PM, Jun Young Kim wrote:

> 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

? ??

4/20/2009 3:05:00 AM

0

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:
> A lot of times, closing the writing stream will trigger the output. =20=

> Hope that helps.


Robert Klemme

4/20/2009 7:11:00 AM

0

2009/4/20 Jun Young Kim <jykim@altibase.com>:
> 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


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...