mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-28 11:05:17 +03:00
30 lines
846 B
Idris
30 lines
846 B
Idris
import System
|
|
import System.File
|
|
import System.Info
|
|
import Data.Strings
|
|
|
|
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
|
|
pclose fh
|
|
putStrLn "closed"
|
|
let [idris2, _] = split ((==) ',') output
|
|
| _ => printLn "Unexpected result"
|
|
putStrLn idris2
|