command-qq-0.2.1.0: Quasiquoters for external commands

Safe HaskellSafe-Inferred
LanguageHaskell2010

System.Command.QQ.Eval

Description

Evalute passed arguments with external interpreter

Synopsis

Documentation

class Eval r where Source

Different interesting return types for quasiquoters

Instances here mostly resemble the types of things in System.Process

Methods

eval :: String -> [String] -> r Source

Instances

Eval (IO String)

Return stdout of external process as String

Does not care whether external process has failed or not.

>>> [sh|echo -n hello world|] :: IO String
"hello world"
Eval (IO ())

The most basic instance: nothing is known about what happened in external command

External command's stdout and stderr go to caller's stdout and stderr respectively

>>> [sh|echo hello world|] :: IO ()
hello world
((~) * s ExitCode, (~) * o Text, (~) * e Text) => Eval (IO (s, o, e))

Return exit code, stdout, and stderr of external process

>>> [sh|echo hello world; echo bye world >&2; exit 1|] :: IO (ExitCode, Text, Text)
(ExitFailure 1,"hello world\n","bye world\n")
Eval (IO ExitCode)

Return exit code of the external process

>>> [sh|exit 0|] :: IO ExitCode
ExitSuccess
>>> [sh|exit 7|] :: IO ExitCode
ExitFailure 7
Eval (IO Text)

Return stdout of the external process as Text

Does not care whether external process has failed or not.

>>> [sh|echo -n hello world|] :: IO Text
"hello world"
((~) * i Text, (~) * o (ExitCode, Text, Text)) => Eval (i -> IO o)

Return exit code, stdout, and stderr of the external process and pass supplied Text to its stdin

>>> [sh|while read line; do echo ${#line}; done|] "hello\nworld!\n"
(ExitSuccess,"5\n6\n","")