2020-05-23 19:42:05 +03:00
|
|
|
import System
|
|
|
|
import System.File
|
2020-05-28 17:42:56 +03:00
|
|
|
import System.Info
|
2020-08-04 22:03:18 +03:00
|
|
|
import Data.List1
|
2021-06-28 15:48:37 +03:00
|
|
|
import Data.String
|
2020-05-23 19:42:05 +03:00
|
|
|
|
2020-05-28 17:42:56 +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)
|
|
|
|
|
2020-05-23 19:42:05 +03:00
|
|
|
main : IO ()
|
|
|
|
main = do
|
|
|
|
Just cmd <- getEnv "POPEN_CMD"
|
|
|
|
| Nothing => putStrLn "POPEN_CMD env var not set"
|
2020-05-28 17:42:56 +03:00
|
|
|
let cmd = if isWindows then windowsPath cmd else cmd
|
2020-05-23 19:42:05 +03:00
|
|
|
Right fh <- popen cmd Read
|
|
|
|
| Left err => printLn err
|
|
|
|
putStrLn "opened"
|
|
|
|
Right output <- fGetLine fh
|
|
|
|
| Left err => printLn err
|
|
|
|
pclose fh
|
|
|
|
putStrLn "closed"
|
2020-09-22 17:07:40 +03:00
|
|
|
let (idris2 ::: _) = split ((==) ',') output
|
2020-05-23 19:42:05 +03:00
|
|
|
| _ => printLn "Unexpected result"
|
|
|
|
putStrLn idris2
|