Mkfifo on windows

windoze types-

i have a ruby module, spawn (like popen3 w/o a fork), that relies on a system
call to ‘mkfifo’. currenlty i’m just using a system call because just about
any system with for should also have a ‘mkfifo’ call. i’m considering making
this a c extension but am unsure if windows has a posix compliant mkfifo call?
i realize this is slightly off topic but the spawn method is really useful and
seems to be quite a bit faster than popen3 as well.

thanks

-a

btw. here is the ‘baby’ code for Spawn:

#!/usr/bin/env ruby
require ‘open3’
require ‘tmpdir’
require ‘io/wait’

$VERBOSE=nil

module Spawn
class << self
def spawn cmd
ipath, opath, epath = tmpfifo, tmpfifo, tmpfifo
system “#{ cmd } < #{ ipath } 1> #{ opath } 2> #{ epath } &”
[open(ipath, ‘w’), open(opath, ‘r’), open(epath, ‘r’)]
end
def tmpfifo
path = nil
42.times do |i|
tpath = File.join(Dir.tmpdir, “#{ $$ }.#{ rand }.#{ i }”)
system “mkfifo #{ tpath }” # how to do this in windows, C or shell?
next unless $? == 0
path = tpath
at_exit{ File.unlink(path) rescue STDERR.puts(“rm <#{ path }> failed”) }
break
end
raise “could not generate tmpfifo” unless path
path
end
end
end

if $0 == FILE
mode = ARGV.shift || ‘open3’

program = <<-stmts
echo 42
sleep 1
echo 42
sleep 1
echo done # signals end of stdout
echo done 1>&2 # signals end of stderr
stmts

done = %r/^\s*done\s*$/o

thread =
Thread.new do
i,o,e = (mode =~ /open3/io ? Open3::popen3(‘sh’) : Spawn::spawn(‘sh’))

Thread.new do
  Thread.new do
    program.each{|stmt| i.puts stmt}
    i.flush
  end.join
end

rfds = [o,e]
loop do
  break if rfds.empty?
  rs, = select rfds, nil, nil
  rs.each do |r|
    rfds.delete(r) and next if r.eof?
    line = ''
    line << r.getc while r.ready? 
    rfds.delete(r) and line[done]='' if line =~ done 
    next if line.empty?
    printf "%s @ %s: %s\n", (r == o ? 'o' : 'e'), Time.now.to_f, line.inspect
  end
end

end

thread.join
end

-a

···

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================

Ara.T.Howard wrote:

windoze types-

yeah, whaddyawant ? :>

but am unsure if windows has a posix compliant mkfifo call?

I think not.
Having http://unxutils.sourceforge.net/ installed with a
mkfifo.exe included, led me to try it. Further research
revealed that it’s a dummy prog that outputs:

“D:\UNIX\USR\LOCAL\WBIN\MKFIFO.EXE: fifo files not supported”

require ‘io/wait’

io/wait may be standard lib, but it doesn’t install on bccwin32
(headers sys/ioctl.h, sys/filio.h not available)

<mkmf.log for io/wait>
"cpp32 -ID:/ruby/SOURCE~1/cvs_head/bccwin32 -ID:/RUBY/SOURCE~1/CVS_HEAD -I. -ID:/RUBY/SOURCE~1/CVS_HEAD/BCC32/…/ -ID:/RUBY/SOURCE~1
/CVS_HEAD/BCC32/…/missing /q /k- /w- /v- /O2 conftest.c "
conftest.c:
checked program was:
/* begin */
#include <ruby.h>
/top/
#ifndef DOSISH

error

#endif
/* end */
</mkmf.log>

That doesn’t seem to indicate an error but it still doesn’t run the makefile.

  • can’t see it in a PragProg mswin32 install, either.

echo done 1>&2 # signals end of stderr

This form doesn’t work on Win9x, WinNT only ?
(perhaps you’re not using it in the main prog, but FYI)

Hope that doesn’t permanently deter you from multi-platform consideration.

daz

“daz” dooby@d10.karoo.co.uk schrieb im Newsbeitrag
news:Q2-dnYYxj9NTifvdSa8jmw@karoo.co.uk

Ara.T.Howard wrote:

windoze types-

yeah, whaddyawant ? :>

but am unsure if windows has a posix compliant mkfifo call?

I think not.
Having http://unxutils.sourceforge.net/ installed with a
mkfifo.exe included, led me to try it. Further research
revealed that it’s a dummy prog that outputs:

“D:\UNIX\USR\LOCAL\WBIN\MKFIFO.EXE: fifo files not supported”

This is what cygwin says:

13:28:30 [temp]: mkfifo XXXXXX
mkfifo: cannot create fifo ``XXXXXX’': Function not implemented

And I thought there were named pipes on Windows. Hm… Nobu, what do you
say? Usually you know these things… :slight_smile:

Regards

robert

This may be of some help:

MSDN reference on the CreateNamedPipe function.

There’s links at the bottom to other named pipe related functions, as well as
a reference on windows pipes in general.

I didn’t look it over too much, but the fact that there’s special functions to
work with named pipes makes me wonder if they work like Unix named pipes.
There’s a special function just to connect to them, so I don’t know if they
work just like files.

Anyhow, if worse came to worst, one could probably use that to write a
mkfifo. Hope this helps.

  • Dan
···

On Monday 29 March 2004 6:34 am, Robert Klemme wrote:

This is what cygwin says:

13:28:30 [temp]: mkfifo XXXXXX
mkfifo: cannot create fifo ``XXXXXX’': Function not implemented

And I thought there were named pipes on Windows. Hm… Nobu, what do you
say? Usually you know these things… :slight_smile:

this look promising. i was under the impression thet fifo’s were a posix
thing and so at least some of the newer windwows would support them. that
capability make possible interesting maipulations of processes stdout and
stderr’s w/o using a fork…

-a

···

On Mon, 29 Mar 2004, Dan Doel wrote:

On Monday 29 March 2004 6:34 am, Robert Klemme wrote:

This is what cygwin says:

13:28:30 [temp]: mkfifo XXXXXX
mkfifo: cannot create fifo ``XXXXXX’': Function not implemented

And I thought there were named pipes on Windows. Hm… Nobu, what do you
say? Usually you know these things… :slight_smile:

This may be of some help:

Technical documentation | Microsoft Learn

MSDN reference on the CreateNamedPipe function.

There’s links at the bottom to other named pipe related functions, as well as
a reference on windows pipes in general.

I didn’t look it over too much, but the fact that there’s special functions to
work with named pipes makes me wonder if they work like Unix named pipes.
There’s a special function just to connect to them, so I don’t know if they
work just like files.

Anyhow, if worse came to worst, one could probably use that to write a
mkfifo. Hope this helps.

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================

this look promising. i was under the impression thet fifo’s were a
posix
thing and so at least some of the newer windwows would support them.
that
capability make possible interesting maipulations of processes stdout
and
stderr’s w/o using a fork…

Any examples? I am always interested in new ways to do this type of
manipulations, especially in a platform indepedent manner (not the case
here apparently).

Guillaume.

···

-a

=======================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print
"\x3a\x2d\x29\x0a"”;done
=======================================================================
========