diff --git a/examples/09-processes.hell b/examples/09-processes.hell index e029a29..5dfffda 100644 --- a/examples/09-processes.hell +++ b/examples/09-processes.hell @@ -14,4 +14,7 @@ main = do let config = Process.proc "false" [] code <- Process.runProcess config + + Process.runProcess $ Process.setWorkingDir "/etc/" $ Process.proc "pwd" [] + Text.putStrLn "Done." diff --git a/examples/31-open-file-handle.hell b/examples/31-open-file-handle.hell new file mode 100644 index 0000000..9d900ba --- /dev/null +++ b/examples/31-open-file-handle.hell @@ -0,0 +1,10 @@ +main = do + let filepath = "out.txt" + handle <- IO.openFile filepath IO.WriteMode + let proc = Process.setStdout (Process.useHandleClose handle) $ + Process.proc "ls" ["-al"] + Process.runProcess_ proc + IO.hClose handle + + contents <- Text.readFile filepath + Text.putStrLn contents diff --git a/src/Hell.hs b/src/Hell.hs index 4f0e407..b536124 100644 --- a/src/Hell.hs +++ b/src/Hell.hs @@ -1229,6 +1229,11 @@ supportedLits = ("IO.LineBuffering", lit' IO.LineBuffering), ("IO.BlockBuffering", lit' IO.BlockBuffering), ("IO.hClose", lit' IO.hClose), + ("IO.openFile", lit' (\f m -> IO.openFile (Text.unpack f) m)), + ("IO.ReadMode", lit' IO.ReadMode), + ("IO.WriteMode", lit' IO.WriteMode), + ("IO.AppendMode", lit' IO.AppendMode), + ("IO.ReadWriteMode", lit' IO.ReadWriteMode), -- Concurrent stuff ("Concurrent.threadDelay", lit' Concurrent.threadDelay), -- Bool @@ -1600,8 +1605,9 @@ polyLits = "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 () - "Process.useHandleOpen" useHandleOpen :: forall (a :: StreamType). IO.Handle -> StreamSpec a () + "Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a () + "Process.useHandleOpen" useHandleOpen :: forall (a :: StreamType). IO.Handle -> StreamSpec a () + "Process.setWorkingDir" process_setWorkingDir :: forall a b c. Text -> ProcessConfig a b c -> ProcessConfig a b c |] ) @@ -1770,6 +1776,12 @@ temp_withSystemTempFile template action = Temp.withSystemTempFile (Text.unpack t temp_withSystemTempDirectory :: forall a. Text -> (Text -> IO a) -> IO a temp_withSystemTempDirectory template action = Temp.withSystemTempDirectory (Text.unpack template) $ \fp -> action (Text.pack fp) +-------------------------------------------------------------------------------- +-- Process operations + +process_setWorkingDir :: forall a b c. Text -> ProcessConfig a b c -> ProcessConfig a b c +process_setWorkingDir filepath = Process.setWorkingDir (Text.unpack filepath) + -------------------------------------------------------------------------------- -- Inference type representation