Skip to content

Commit

Permalink
Merge pull request haskell#69 from JonCoens/withCreateProcess
Browse files Browse the repository at this point in the history
Expose withCreateProcess to users.
  • Loading branch information
snoyberg authored Aug 11, 2016
2 parents 5616568 + 2398a4c commit 18bb13c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 10 additions & 11 deletions System/Process.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module System.Process (
readProcess,
readCreateProcessWithExitCode,
readProcessWithExitCode,
withCreateProcess,

-- ** Related utilities
showCommandForUser,
Expand Down Expand Up @@ -196,29 +197,27 @@ createProcess cp = do
maybeCloseStd _ = return ()

{-
-- TODO: decide if we want to expose this to users
-- | A 'C.bracketOnError'-style resource handler for 'createProcess'.
-- | A 'C.bracket'-style resource handler for 'createProcess'.
--
-- In normal operation it adds nothing, you are still responsible for waiting
-- for (or forcing) process termination and closing any 'Handle's. It only does
-- automatic cleanup if there is an exception. If there is an exception in the
-- body then it ensures that the process gets terminated and any 'CreatePipe'
-- 'Handle's are closed. In particular this means that if the Haskell thread
-- is killed (e.g. 'killThread'), that the external process is also terminated.
-- Does automatic cleanup when the action finishes. If there is an exception
-- in the body then it ensures that the process gets terminated and any
-- 'CreatePipe' 'Handle's are closed. In particular this means that if the
-- Haskell thread is killed (e.g. 'killThread'), that the external process is
-- also terminated.
--
-- e.g.
--
-- > withCreateProcess (proc cmd args) { ... } $ \_ _ _ ph -> do
-- > ...
--
-}
withCreateProcess
:: CreateProcess
-> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> IO a)
-> IO a
withCreateProcess c action =
C.bracketOnError (createProcess c) cleanupProcess
(\(m_in, m_out, m_err, ph) -> action m_in m_out m_err ph)
-}
C.bracket (createProcess c) cleanupProcess
(\(m_in, m_out, m_err, ph) -> action m_in m_out m_err ph)

-- wrapper so we can get exceptions with the appropriate function name.
withCreateProcess_
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for [`process` package](http://hackage.haskell.org/package/process)

## Unreleased

* New exposed `withCreateProcess`

## 1.4.2.0 *January 2016*

* Added `createPipeFD` [#52](https://github.com/haskell/process/pull/52)
Expand Down

0 comments on commit 18bb13c

Please sign in to comment.