Idris2/tests/node/node020/Popen.idr

30 lines
832 B
Idris
Raw Normal View History

2020-06-12 23:35:08 +03:00
import System
import System.File
import System.Info
import Data.String
import Data.List1
2020-06-12 23:35:08 +03:00
windowsPath : String -> String
windowsPath path =
let replaceSlashes : List Char -> List Char
replaceSlashes [] = []
replaceSlashes ('/' :: cs) = '\\' :: replaceSlashes cs
replaceSlashes (c :: cs) = c :: replaceSlashes cs
in
pack $ replaceSlashes (unpack path)
main : IO ()
main = do
Just cmd <- getEnv "POPEN_CMD"
| Nothing => putStrLn "POPEN_CMD env var not set"
let cmd = if isWindows then windowsPath cmd else cmd
Right fh <- popen cmd Read
| Left err => printLn err
putStrLn "opened"
Right output <- fGetLine fh
| Left err => printLn err
2021-11-03 18:10:43 +03:00
ignore $ pclose fh
2020-06-12 23:35:08 +03:00
putStrLn "closed"
let (idris2 ::: _) = split ((==) ',') output
2020-06-12 23:35:08 +03:00
putStrLn idris2