Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.3.2
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 32 lines (25 sloc) 0.993 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
{-|
Author : Sergei Trofimovich <slyfox@inbox.ru>
Stability : experimental
Portability : haskell98

Ungrouped utilitary stuff lays here until someone finds better place for it :]
-}

module Util
    ( run_cmd -- :: String -> IO (Maybe String)
    ) where

import System.IO
import System.Process
import System.Exit (ExitCode(..))

-- 'run_cmd' executes command and returns it's standard output
-- as 'String'.

run_cmd :: String -> IO (Maybe String)
run_cmd cmd = do (hI, hO, hE, hProcess) <- runInteractiveCommand cmd
                 hClose hI
                 output <- hGetContents hO
                 errors <- hGetContents hE -- TODO: propagate error to caller
                 length output `seq` hClose hO
                 length errors `seq` hClose hE

                 exitCode <- waitForProcess hProcess
                 return $ if (output == "" || exitCode /= ExitSuccess)
                          then Nothing
                          else Just output
Something went wrong with that request. Please try again.