
On Thu, 2007-12-13 at 15:48 +0300, Bulat Ziganshin wrote:
Hello haskell-cafe,
please help me with selection of proper function to use
i need to run external command with parameter and get its stdout, smth like this:
output <- system "cmd param"
the code should be compatible with unix and windows, and it should be possible to execute scripts (so afaiu it should execute command via cmd/sh). i use ghc 6.6.1 and it will be great if this function will not require any non-bundled libs and be compatible with later ghc versions
There is rawSystemStdout in Cabal which you might like to copy. It is portable to windows and several Haskell compilers but does use cpp to achieve that. It's also rather inefficient as it has to create a temporary file. It seems it is not possible to use pipes to get the stdout and have the resulting code be portable between Haskell implementations (it's a favourite peeve of mine). As the name suggests, rawSystemStdout uses rawSystem so does not necessarily do what you want with cmd/sh but you could easily adapt it to use system rather than rawSystem. http://darcs.haskell.org/cabal/Distribution/Simple/Utils.hs http://darcs.haskell.org/cabal/Distribution/Compat/TempFile.hs Duncan