From: Brian Candler Date: 2003-05-20T20:23:02+09:00 Subject: Re: Named Pipes On Tue, May 20, 2003 at 08:02:34PM +0900, Mark Firestone wrote: > Martin Demello and I have written an old style multiline (with threads) BBS > in Ruby. It runs on linux. There are lots of old dos games for BBSes that > run under, well, dos. > > So, I got this crazy idea one day... I can run them under dosemu, and pipe > the input and output though the BBS program, to the user. > > I wrote (with some help from the list) a little piece of code that does > this with unnamed pipes, which works fine for "regular" apps that use stin > and stout, but not for doseum > > When I am using dosemu, I only get the input... stuff I send to it doesn't > get there... It turns out it has a -U switch, that is supposed to make it > use named pipes. You specify the pipes on the command line. > > I wrote a piece of code that should do this, but everything locks. I'm not > sure if it is me or this app. Is there a convention regarding where named > pipes get placed? Maybe that is part of the problem... I'm putting these > in the same directory as the app. maybe that is wrong. It ought to be fine, it doesn't matter where they are as long as the permissions as OK for opening them. You should probably confirm that dosemu is working in the way that you expect (i.e. it is in fact responding on the named pipes), or try some alternatives (e.g. FreeBSD has 'pcemu' in the ports collection) It's easy enough to demonstrate named pipes in Ruby: $ mkfifo p1 $ mkfifo p2 [pipe1.rb] rd = File.open("p1","r") wr = File.open("p2","w") line = rd.gets wr.puts "Hello, you said #{line}" [pipe2.rb] wr = File.open("p1","w") rd = File.open("p2","r") Thread.new do wr.print "wibble" wr.close end ans = rd.read rd.close puts "Finished. Result was: #{ans}" Run pipe1.rb in one window, and pipe2.rb in another. Make sure you deal with concurrency issues properly: i.e. you should have separate threads for reading to and writing from your DOS application, if you don't want to deadlock. Pipes only have a limited capacity (typically 8KB) so you need to make sure they don't get full, otherwise the writer will block until the reader accepts some data. If this is a multi-user system then you'll need separate named pipes for each user, of course. Regards, Brian.