Proposal: overhaul System.Process

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Tue Apr 22 19:28:44 EDT 2008


On Tue, 2008-04-22 at 16:09 -0700, Don Stewart wrote:
> duncan.coutts:

> > > readProcess :: FilePath                     -- ^ command to run
> > >             -> [String]                     -- ^ any arguments
> > >             -> String                       -- ^ standard input
> > >             -> IO (Either (ExitCode,String) String)  -- ^ either the stdout, or an exitcode and any output
> > 
> > You don't need the Either. ExitCode already covers the case when the
> > process terminates successfully.
> > 
> 
> But we want to force people to check the failure case. Just returning
> the tuple doesn't help there.

In Cabal we have two versions:

usualConvenientVersion :: FilePath -> [String] -> IO String

moreGeneralVersion :: FilePath -> [String] -> IO (String, ExitCode)

The first version - that we expect to use most often - just throws an
exception if the exit code is non-0. In our experience this is almost
always the right thing to do. There is only one place in Cabal where we
expect the command to fail but we need the output anyway. We previously
had all our process functions return an ExitCode and they were routinely
ignored. I suppose the fact that with readProcess people will be
interested in the result does help the situation.

Duncan



More information about the Libraries mailing list