Skip to content

Commit

Permalink
Add more process functions and a motivating example (#73)
Browse files Browse the repository at this point in the history
* make `Process.runProcess` and `Process.runProcess_` polymorphic over streams

* add `Process.setStdout` and `Process.useHandleClose` primitives

* create example of using a handle for the stdout of a process
  • Loading branch information
austin-artificial authored Jan 7, 2025
1 parent c60d0df commit 78c8647
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions examples/30-process-handlers.hell
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
main = do
Temp.withSystemTempFile "example" \filePath handle -> do
Text.putStrLn $ Text.concat ["Created temp file ", filePath]
let proc = Process.setStdout (Process.useHandleClose handle) $
Process.proc "ls" ["-al"]
Process.runProcess_ proc
contents <- Text.readFile filePath
Text.putStrLn contents
8 changes: 6 additions & 2 deletions src/Hell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,8 +1250,7 @@ supportedLits =
-- Process
("Process.proc", lit' $ \n xs -> proc (Text.unpack n) (map Text.unpack xs)),
("Process.setEnv", lit' $ Process.setEnv @() @() @() . map (bimap Text.unpack Text.unpack)),
("Process.runProcess", lit' $ runProcess @IO @() @() @()),
("Process.runProcess_", lit' $ runProcess_ @IO @() @() @()),

-- Exit
("Exit.ExitSuccess", lit' Exit.ExitSuccess),
("Exit.ExitFailure", lit' Exit.ExitFailure),
Expand Down Expand Up @@ -1594,6 +1593,11 @@ polyLits =
-- Temp
"Temp.withSystemTempFile" temp_withSystemTempFile :: forall a. Text -> (Text -> IO.Handle -> IO a) -> IO a
"Temp.withSystemTempDirectory" temp_withSystemTempDirectory :: forall a. Text -> (Text -> IO a) -> IO a
-- Process
"Process.runProcess" runProcess :: forall a b c. ProcessConfig a b c -> IO ExitCode
"Process.runProcess_" runProcess_ :: forall a b c. ProcessConfig a b c -> IO ()
"Process.setStdout" setStdout :: forall stdin stdout stdout' stderr. StreamSpec 'STOutput stdout' -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout' stderr
"Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
|]
)

Expand Down

0 comments on commit 78c8647

Please sign in to comment.