posix, POpen, ghc 6.5
Frederik Eaton
frederik at a5.repetae.net
Wed Jan 11 19:05:18 EST 2006
(forgot to Cc list, sorry)
On Mon, Jan 09, 2006 at 10:11:23AM +0000, Simon Marlow wrote:
> Frederik Eaton wrote:
> >I'm not sure what's happened, I'm getting strange errors, it seems
> >like a lot of packages have changed names in ghc 6.5. For instance,
> >'posix' is missing from the output of 'ghc-pkg list --global' and I
> >don't know where to find POpen. /home/frederik/arch/i386//lib/ghc-6.5.20060106/package.conf:
> > Cabal-1.0, GLUT-2.0, HGL-3.1, HUnit-1.1, OpenGL-2.1,
> > QuickCheck-1.0, X11-1.1, base-1.0, fgl-5.2, (ghc-6.5.20060106),
> > haskell-src-1.0, haskell98-1.0, hsql-1.7, hsql-mysql-1.7, mtl-1.0,
> > network-1.0, parsec-2.0, readline-1.0, rts-1.0, stm-1.0,
> > template-haskell-1.0, unix-1.0
> >'popen' doesn't seem to appear in the documentation. Has it been
> >removed? If so, that seems slightly unfair. I remember trying to write
> >something using runProcess or runInteractiveProcess recently and
> >finding those buggy. It would be nice to have some measure of
> >stability.
>
> popen and the posix package have been deprecated for quite some time now. If you're having
> problems with System.Process, please submit bug reports - there's one outstanding bug that I'm
> aware of, but it doesn't seem critical: http://cvs.haskell.org/trac/ghc/ticket/431.
That seems like a critical bug to me. What if I want to use Haskell to
write a daemon which closes its standard input, yet uses a library
based on runInteractiveProcess? Do I have to contact the library
authors and have them rewrite their library for every new ghc release
(since they would have had to have been using popen until now), or
should I just settle with things not functioning?
Here is the output of a small test program (attached). If I compile
this particular example, then it works, but when I use 'runghc' it
doesn't. I seem to remember it being broken while testing in ghci as
well. This is why *I* am using 'popen'. Have I made a mistake?
$ ./test-proc.hs
here0
here1
here2
here3
here4 [ here it hangs and i press ^C ]
runghc: waitForProcess: interrupted (Interrupted system call)
[1]$ which runghc
/usr/bin/runghc
$ runghc --version
runghc: syntax: runghc [-f GHCPATH] [GHC-ARGS] FILE ARG...
[1]$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.4.1
$ which ghc
/usr/bin/ghc
I vaguely remember hearing that POpen has been deprecated (where is it
documented?), and I like the new interface which was been provided,
but I think that the new interface should be stable and bug-free for
at least a few minor versions before the POpen module is removed. And
why not provide a compatibility wrapper? I don't see the point of
forcing people to change working code.
Frederik
-------------- next part --------------
#!/usr/bin/runghc
import System.IO
import System.Posix.Process
import System.Posix.Files
import System.Posix.IO
import System.Process
import System.Directory
import System.Exit
import System.Environment
import Control.Concurrent
import Control.Exception
saferunioprog :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String,String)] -> String -> IO (String, ExitCode)
saferunioprog prog args cwd env input = do
(hin,hout,herr,ph) <- runInteractiveProcess prog args cwd env
putStrLn "here0"
forkIO (do hPutStr hin input; hClose hin)
putStrLn "here1"
out <- hGetContents hout
putStrLn "here2"
err <- hGetContents herr
putStrLn "here3"
forkIO (putStrLn err)
forkIO (putStrLn out)
putStrLn "here4"
ec <- waitForProcess ph
putStrLn "here5"
return (out, ec)
main = do
saferunioprog "cat" [] Nothing Nothing "blah"
More information about the Glasgow-haskell-bugs
mailing list