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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7caba80fca2ac4ddbb7f55957e5c0dec?d=identicon&s=25 Jun Young Kim (Guest)
on 2009-04-20 04:20
(Received via mailing list)
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??
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2009-04-20 04:43
(Received via mailing list)
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
7caba80fca2ac4ddbb7f55957e5c0dec?d=identicon&s=25 Jun Young Kim (Guest)
on 2009-04-20 05:05
(Received via mailing list)
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.

2009. 04. 20, 오전 11:43, James Gray 작성:
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-04-20 09:11
(Received via mailing list)
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
This topic is locked and can not be replied to.