# Another popen question...the ruby bbs

**URL:** <https://rubytalk.org/t/another-popen-question-the-ruby-bbs/6007>\
**Category:** ruby-talk\
**Created:** [16 May 2003 00:55 UTC](https://rubytalk.org/t/another-popen-question-the-ruby-bbs/6007 "2003-05-16T00:55:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Firestone2](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mark\_Firestone2](https://rubytalk.org/u/Mark_Firestone2)\
**Post date:** [16 May 2003 00:55 UTC](https://rubytalk.org/t/another-popen-question-the-ruby-bbs/6007/1 "2003-05-16T00:55:55Z")

</div>

All this talk of popen put me in mind of something. I could use it to link the Ruby BBS to external programs, specifically all those old dos door games by using dosemu and redirecting the output…

I got it to get the data from the application ok, but I can’t figure out how to get data to the application… nothing seems to be happening when I write data to the external process… any ideas, advice, boots to the head would be appreciated (keeping in mind that it is now 2am…)

def doortest

begin  
pipe = IO.popen("./dosemu,“w+”)  
while true  
puts (“loop…”)  
if select([pipe],nil,nil,0.1) !=nil  
char = pipe.getc

```
puts "char: #{char}"
  #if char != nil
   @socket.write (char.chr)
   @socket.write CR.chr if char == LF
  else
   if select([@socket],nil,nil,0.1) != nil
   puts "socket hit"

    char = @socket.getc
puts char.chr
    pipe.putc(char.chr) if char != nil

   end
  end
 end
rescue
 print ("\r\nDisconnected from Application...\r\n")
 pipe.close
end

```

end

Thanks!

Mark Firestone

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [16 May 2003 01:30 UTC](https://rubytalk.org/t/another-popen-question-the-ruby-bbs/6007/2 "2003-05-16T01:30:42Z")

</div>

Hi,

> All this talk of popen put me in mind of something. I could  
> use it to link the Ruby BBS to external programs,  
> specifically all those old dos door games by using dosemu and  
> redirecting the output…
> 
> I got it to get the data from the application ok, but I can’t  
> figure out how to get data to the application… nothing  
> seems to be happening when I write data to the external  
> process… any ideas, advice, boots to the head would be  
> appreciated (keeping in mind that it is now 2am…)

I don’t know about that “old dos door game”, does it read from  
stdin certainly?

> ```
> while true
> puts ("loop...")
> 
> ```
> 
> if select([pipe],nil,nil,0.1) !=nil

Separating select call would not be nice.

```
while ios = select([pipe, @socket])
  r, * = ios
  if r.include?(pipe)
char = pipe.getc

puts "char: #{char}"
@socket.write ?\r if char == LF
@socket.write(char.chr)
  end
  if r.include?(@socket)
    puts "socket hit"
    char = @socket.getc
puts char.chr
    pipe.putc(char.chr) if char
  end
end

```

> **···**
>
> At Fri, 16 May 2003 09:55:55 +0900, nedry wrote:
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Guillaume\_Marcais1](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Guillaume\_Marcais1](https://rubytalk.org/u/Guillaume_Marcais1)\
**Post date:** [16 May 2003 01:58 UTC](https://rubytalk.org/t/another-popen-question-the-ruby-bbs/6007/3 "2003-05-16T01:58:31Z")

</div>

You probably need to flush your data after writing or change the sync  
flag of your IO stream. Unlike stdout, the pipe is not flushed after a  
“\n”.

Guillaume.

> **···**
>
> Le jeudi, 15 mai 2003, à 20:55 US/Eastern, nedry a écrit :
> 
> > All this talk of popen put me in mind of something. I could use it to  
> > link the Ruby BBS to external programs, specifically all those old dos  
> > door games by using dosemu and redirecting the output…
> > 
> > I got it to get the data from the application ok, but I can’t figure  
> > out how to get data to the application… nothing seems to be  
> > happening when I write data to the external process… any ideas,  
> > advice, boots to the head would be appreciated (keeping in mind that  
> > it is now 2am…)
> > 
> > def doortest
> > 
> > begin  
> > pipe = IO.popen("./dosemu,“w+”)  
> > while true  
> > puts (“loop…”)  
> > if select([pipe],nil,nil,0.1) !=nil  
> > char = pipe.getc
> > 
> > ```
> > puts "char: #{char}"
> > #if char != nil
> > @socket.write (char.chr)
> > @socket.write CR.chr if char == LF
> > else
> > if select([@socket],nil,nil,0.1) != nil
> > puts "socket hit"
> > 
> > char = @socket.getc
> > 
> > ```
> > 
> > puts char.chr  
> > pipe.putc(char.chr) if char != nil
> > 
> > ```
> > end
> > end
> > end
> > rescue
> > print ("\r\nDisconnected from Application...\r\n")
> > pipe.close
> > end
> > 
> > ```
> > 
> > end
> > 
> > Thanks!
> > 
> > Mark Firestone

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [16 May 2003 03:17 UTC](https://rubytalk.org/t/another-popen-question-the-ruby-bbs/6007/4 "2003-05-16T03:17:27Z")

</div>

Hi,

> **···**
>
> At Fri, 16 May 2003 10:58:31 +0900, Guillaume Marcais wrote:
> 
> > You probably need to flush your data after writing or change the sync  
> > flag of your IO stream. Unlike stdout, the pipe is not flushed after a  
> > “\n”.
> 
> Pipes for write are always set sync mode at creation.
> 
> r,w = IO.pipe; p [r.sync, w.sync]
> 
> # =\> [false, true]
> 
> –  
> Nobu Nakada
