2023-04-15 17:39:17 +03:00
|
|
|
import System.File
|
|
|
|
|
2023-12-11 15:50:12 +03:00
|
|
|
runPopen2 : (cmd : String) -> IO ()
|
|
|
|
runPopen2 cmd = do
|
2023-12-09 20:15:09 +03:00
|
|
|
putStrLn "main thread: before all"
|
2023-12-11 15:50:12 +03:00
|
|
|
Right process <- popen2 cmd
|
2023-04-15 17:39:17 +03:00
|
|
|
| Left err => printLn err
|
|
|
|
printLn $ process.pid > 0
|
|
|
|
_ <- fPutStrLn process.input "Hello, Idris!\n"
|
2023-12-09 20:15:09 +03:00
|
|
|
putStrLn "main thread: before closing subinput"
|
2023-04-15 17:39:17 +03:00
|
|
|
closeFile process.input
|
2023-12-09 20:15:09 +03:00
|
|
|
putStrLn "main thread: before reading suboutput"
|
2023-04-15 17:39:17 +03:00
|
|
|
Right result <- fRead process.output
|
|
|
|
| Left err => printLn err
|
2023-12-09 20:15:09 +03:00
|
|
|
putStrLn "main thread: before printing suboutput"
|
2023-04-15 17:39:17 +03:00
|
|
|
putStr result
|
2023-12-11 15:50:12 +03:00
|
|
|
putStrLn "main thread: before waiting subprocess"
|
|
|
|
exitCode <- popen2Wait process
|
|
|
|
putStrLn "subprocess exit code: \{show exitCode}"
|
2023-12-09 20:15:09 +03:00
|
|
|
putStrLn "main thread: after all"
|
2023-12-11 15:50:12 +03:00
|
|
|
|
|
|
|
main : IO ()
|
|
|
|
main = runPopen2 "cat"
|
|
|
|
|
|
|
|
main2 : IO ()
|
|
|
|
main2 = runPopen2 "cat && exit 4"
|
|
|
|
|
|
|
|
main3 : IO ()
|
|
|
|
main3 = runPopen2 "cat && echo \"Two spaces\" && exit 4"
|