I’ve got a Haskell program that needs to execute a separate (third party) binary; this binary will write its output to a file provided as a command-line argument (it does not seem willing to write to STDOUT). I see that System.Cmd will allow me to call this binary, but I’m quite mystified by the type of withTemporaryDirectory. Namely:
withTemporaryDirectory :: FilePath -> (FilePath -> IO a) -> IO a
whereas System.Cmd merely gives me:
rawSystem :: String -> [String] -> IO ExitCode
(as well as system, which isn’t usefully different in this case).
I’m just stuck figuring out how to wire these up; I want to create a temp directory (this binary likes to vomit all over its CWD), run the binary, read from its output file (I’ll know its name as I provide that as an argument to the binary in question) and then blow away the temp directory and its contents.
So, should I be writing a function whose type is (Filepath -> IO a) in order to do all the stuff I described? Are there any good examples anyone can provide to this effect?
In this case, the binary being used is PsiPred (protein secondary structure prediction) and while its source is available, I’d rather not have to modify it. This software we’re working on is a computational biology program for remote homology detection in proteins.
FilePathis typdefed as aString.withTemporaryDirectoryworks as if you calledmkdtemp(3)with its first argument, and then used its result to call the second argument (a function taking a path with the template applied, and running an IO action with it). After the inner function terminates, the directory is deleted.In your case, I would assume you should use withTemporaryDirectory, and then inside the function you pass to it, change directories to the temporary one, actually run PsiPred, and then change back into your old one.