Posix.IO.Process

This module provides an API for executing shell commands and spawning child processes.

Blocking API

These operations will spawn a sub-process and wait for it to exit.

exec : String -> IO String Exit

Execute a shell command and wait until it exits.

exec "ls -l"
execFile : String -> List String -> IO String Exit

Execute file with args and wait until it exits.

execFile "path/to/file" [ "arg1", "arg2" ]
type alias Exit =
{ status : Int
, stdOut : String
, stdErr : String
}

Sub-Process exit data.

failOnError : IO String Exit -> IO String String

Make program fail if the status code is not zero. Also unpacks stdOut and stdErr as IO <stdErr> <stdOut>.

exec "whoami"
    |> failOnError
    |> IO.andThen
        (\usename ->
            IO.printLn ("Hello, " ++ username)
        )

Non-Blocking API

spawn : String -> List String -> IO String Process

Spawn a child process without blocking.

spawn cmd args
type alias Process =
{ pid : Pid
, stdIn : Stream Bytes Never
, stdOut : Stream Never Bytes
, stdErr : Stream Never Bytes
}
type Pid
wait : Pid -> IO String Int

Wait for child process to exit.

kill : Signal -> Pid -> IO String ()

Send a signal to a child process.

type Signal
= SIGALRM
| SIGBUS
| SIGCHLD
| SIGCLD
| SIGCONT
| SIGEMT
| SIGFPE
| SIGHUP
| SIGILL
| SIGINFO
| SIGINT
| SIGIO
| SIGIOT
| SIGKILL
| SIGLOST
| SIGPIPE
| SIGPOLL
| SIGPROF
| SIGPWR
| SIGQUIT
| SIGSEGV
| SIGSTKFLT
| SIGSTOP
| SIGTSTP
| SIGSYS
| SIGTERM
| SIGTRAP
| SIGTTIN
| SIGTTOU
| SIGUNUSED
| SIGURG
| SIGUSR1
| SIGUSR2
| SIGVTALRM
| SIGXCPU
| SIGXFSZ
| SIGWINCH