-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
Process.useHandleOpen
primitive (#76)
* add `Process.useHandleOpen` primitive * update process handlers example
- Loading branch information
1 parent
cc10780
commit d5da0d4
Showing
2 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
main = do | ||
-- 1. close the handle after the process | ||
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 | ||
|
||
-- 2. keep the handle open after the process | ||
Temp.withSystemTempFile "example-open" \filePath handle -> do | ||
Text.putStrLn $ Text.concat ["Created temp file ", filePath] | ||
let proc0 = Process.setStdout (Process.useHandleOpen handle) $ | ||
Process.proc "echo" ["hello"] | ||
-- second time around we we make sure to close the handle | ||
-- so we can then read the file later | ||
let proc1 = Process.setStdout (Process.useHandleClose handle) $ | ||
Process.proc "echo" ["world"] | ||
Process.runProcess_ proc0 | ||
Process.runProcess_ proc1 | ||
contents <- Text.readFile filePath | ||
Text.putStrLn contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters