Idris2/tests/base/system_file_popen/Popen.idr

30 lines
822 B
Idris
Raw Normal View History

2021-10-29 18:38:32 +03:00
import Data.String
import System.File
import System.Info
main : IO ()
main = do
Right f <- popen ("echo " ++ escapeArg "Hello, world") Read
| Left err => printLn err
Right contents <- fGetLine f
| Left err => printLn err
printLn $ trim contents
2021-11-03 18:10:43 +03:00
0 <- pclose f
| n => printLn n
2021-10-29 18:38:32 +03:00
let cmd : List String = if not isWindows
then ["printf", "Hello, %s", "$PATH"]
else ["echo", "Hello, $PATH"]
Right f <- popen cmd Read
| Left err => printLn err
Right contents <- fGetLine f
| Left err => printLn err
printLn $ (ifThenElse isWindows trim id) contents
2021-11-03 18:10:43 +03:00
0 <- pclose f
| n => printLn n
Right f <- popen ["exit", "17"] Read
| Left err => printLn err
printLn !(pclose f)