Spawning a process using Hugs/Win32
Graham Klyne
gk at ninebynine.org
Tue Feb 3 16:11:22 EST 2004
I thought I might have a version of POpen that works with Win32/Hugs, but
I'm only slightly successful. The function of POpen is to spawn a
sub-process using the Win32 equivalent of pipes to supply standard input
and to accept standard output and standard error from the spawned process.
My starting point was a module called Win32Spawn, which I found in
hslibs/win32 in the GHC source distribution. I have managed to compile the
accompanying module and FFI interface into a DLL. The files used to do
this are at [1], with the build process outlined in [2].
The key code in the new module POPen.hs [3] is in function "spawn", which
was adapted from the original module "hslibs/win32/Win32Spawn.hs". I had
to change the code for "spawn", because the Hugs interface for function
openFd is has fewer parameters than that provided by GHC. The remaining
parameters seem to be the same as for the GHC version of openFd.
The resulting program has compiled successfully, and the spawned program is
activated as requested (in this case, curl: my evidence is that my
personal firewall is asking me if curl should be allowed to access the
Internet).
But I also get an I/O exception in the calling program, in function spawn,
when trying to open a handle to write the spawned process' standard input
stream. My evidence for this is by this modification to the code:
[[
hIn <- catch (openFd (fromIntegral wIn) False WriteMode False)
(\er -> do { putStrLn ("openFd wIn: "++show er)
; ioError er
}
)
]]
generating this message:
[[
openFd wIn: openFd: does not exist (file does not exist)
]]
My question is this: are there any fundamental differences between GHC and
Hugs, either in the implementation of openFd, or in the FFI interface, that
would cause (what I assume is) a divergence of behaviour? Does anyone have
any other clues what might be going wrong here?
(BTW, I did get the HXml Toolbox to read and parse XML *from the web* using
the internal HTTP library.)
#g
--
[1] http://www.ninebynine.org/Software/HaskellUtils/Win32/
[2] http://www.ninebynine.org/Software/HaskellUtils/Win32/MakePOpenDLL.bat
[3] http://www.ninebynine.org/Software/HaskellUtils/Win32/POpen.hs
[4] http://www.ninebynine.org/Software/HaskellUtils/Win32/Win32Spawn.hs
------------
Graham Klyne
For email:
http://www.ninebynine.org/#Contact
More information about the Libraries
mailing list