-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3170 from buzden/make-able-wait-popen2
[ re #2944, fix ] Make `popen2` be able to not to leak system resources
- Loading branch information
Showing
7 changed files
with
147 additions
and
6 deletions.
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
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
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
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
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,12 +1,29 @@ | ||
import System.File | ||
|
||
main : IO () | ||
main = do | ||
Right process <- popen2 "cat" | ||
runPopen2 : (cmd : String) -> IO () | ||
runPopen2 cmd = do | ||
putStrLn "main thread: before all" | ||
Right process <- popen2 cmd | ||
| Left err => printLn err | ||
printLn $ process.pid > 0 | ||
_ <- fPutStrLn process.input "Hello, Idris!\n" | ||
putStrLn "main thread: before closing subinput" | ||
closeFile process.input | ||
putStrLn "main thread: before reading suboutput" | ||
Right result <- fRead process.output | ||
| Left err => printLn err | ||
putStrLn "main thread: before printing suboutput" | ||
putStr result | ||
putStrLn "main thread: before waiting subprocess" | ||
exitCode <- popen2Wait process | ||
putStrLn "subprocess exit code: \{show exitCode}" | ||
putStrLn "main thread: after all" | ||
|
||
main : IO () | ||
main = runPopen2 "cat" | ||
|
||
main2 : IO () | ||
main2 = runPopen2 "cat && exit 4" | ||
|
||
main3 : IO () | ||
main3 = runPopen2 "cat && echo \"Two spaces\" && exit 4" |
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,3 +1,33 @@ | ||
main thread: before all | ||
True | ||
main thread: before closing subinput | ||
main thread: before reading suboutput | ||
main thread: before printing suboutput | ||
Hello, Idris! | ||
|
||
main thread: before waiting subprocess | ||
subprocess exit code: 0 | ||
main thread: after all | ||
------ | ||
main thread: before all | ||
True | ||
main thread: before closing subinput | ||
main thread: before reading suboutput | ||
main thread: before printing suboutput | ||
Hello, Idris! | ||
|
||
main thread: before waiting subprocess | ||
subprocess exit code: 4 | ||
main thread: after all | ||
------ | ||
main thread: before all | ||
True | ||
main thread: before closing subinput | ||
main thread: before reading suboutput | ||
main thread: before printing suboutput | ||
Hello, Idris! | ||
|
||
Two spaces | ||
main thread: before waiting subprocess | ||
subprocess exit code: 4 | ||
main thread: after all |
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,3 +1,8 @@ | ||
. ../../testutils.sh | ||
|
||
run Test.idr | ||
echo "------" | ||
idris2 --exec main2 Test.idr | ||
echo "------" | ||
idris2 --exec main3 Test.idr | sed 's/^"//' | sed 's/" *$//' | ||
# filtering above is to level differences in quotes echoing by Windows and the rest |