Let’s say you want to quickly get the MD5 sum of a string. You know you have the
md5sum binary on your system, so you don’t bother installing an additional library to do it. Instead you call the
md5sum executable, writing a function which might look like the following:
import System.IO import System.Process getMD5 :: String -> IO String getMD5 s = do (input, output, _, pid) <- runInteractiveCommand "md5sum" hPutStr input s result <- hGetContents output waitForProcess pid return result
Unless you’ve been messing around with
System.Process lately, you probably had to check the docs for which exact function you wanted to use and what arguments to pass it.
Alternatively, you could use the Pipe library:
import System.Process.Pipe getMD5 :: String -> IO String getMD5 = pipeString [("md5sum",)]
You should get the same result either way—but which code do you prefer? I find there’s too much noise in the standard way of doing things, so I wrote Pipe to make things simpler.
Assuming you have the
cabal-install tool installed and working, the easiest way to obtain Pipe is with the
cabal install pipe command.
Otherwise, you can download the source from Hackage, where you can also browse the documentation.
Failing that, the source package for the latest version, 2.1.2, is also available here:
The full list of dependencies, as listed in the
.cabal file, is as follows:
base >= 4 && < 5
filepath >= 1.1 && < 2
process >= 1.0.1 && < 2
unix >= 2.3 && < 3if not on a Windows platform