| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Primitive System.Process simple bindings to Haskell functions |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible #-} |
| 8 |
|
| 9 |
module System.Process.Primitive where |
| 10 |
|
| 11 |
open import Level using (Level) |
| 12 |
open import Agda.Builtin.List |
| 13 |
open import Agda.Builtin.String |
| 14 |
open import Agda.Builtin.Unit |
| 15 |
open import Foreign.Haskell using (Pair) |
| 16 |
open import IO.Primitive.Core using (IO) |
| 17 |
open import System.Exit.Primitive using (ExitCode) |
| 18 |
|
| 19 |
postulate |
| 20 |
|
| 21 |
callCommand : String → IO ⊤ |
| 22 |
system : String → IO ExitCode |
| 23 |
callProcess : String → List String → IO ⊤ |
| 24 |
|
| 25 |
readProcess |
| 26 |
: String -- Filename of the executable |
| 27 |
→ List String -- any arguments |
| 28 |
→ String -- standard input |
| 29 |
→ IO String -- stdout |
| 30 |
|
| 31 |
readProcessWithExitCode |
| 32 |
: String -- Filename of the executable |
| 33 |
→ List String -- any arguments |
| 34 |
→ String -- standard input |
| 35 |
→ IO (Pair ExitCode (Pair String String)) -- exitcode, stdout, stderr |
| 36 |
|
| 37 |
{-# FOREIGN GHC import System.Process #-} |
| 38 |
{-# FOREIGN GHC import qualified Data.Text as T #-} |
| 39 |
{-# FOREIGN GHC import MAlonzo.Code.System.Exit.Primitive #-} |
| 40 |
|
| 41 |
{-# COMPILE GHC callCommand = \ cmd -> callCommand (T.unpack cmd) #-} |
| 42 |
{-# COMPILE GHC system = \ cmd -> fmap fromExitCode (system (T.unpack cmd)) #-} |
| 43 |
{-# COMPILE GHC callProcess = \ exe -> callProcess (T.unpack exe) . map T.unpack #-} |
| 44 |
{-# COMPILE GHC readProcess = \ exe args -> fmap T.pack . readProcess (T.unpack exe) (map T.unpack args) . T.unpack #-} |
| 45 |
{-# COMPILE GHC readProcessWithExitCode = \ exe args stdin -> |
| 46 |
do { (ex, out, err) <- readProcessWithExitCode (T.unpack exe) (map T.unpack args) (T.unpack stdin) |
| 47 |
; pure (fromExitCode ex, (T.pack out, T.pack err)) |
| 48 |
} |
| 49 |
#-} |