interact set:included-with-ghc

interact f takes the entire input from stdin and applies f to it. The resulting string is written to the stdout device. Note that this operation is lazy, which allows to produce output even before all input has been consumed. This operation may fail with the same errors as getContents and putStr.

Examples

>>> interact (\str -> str ++ str)
> hi :)
hi :)
> ^D
hi :)
>>> interact (const ":D")
:D
>>> interact (show . words)
> hello world!
> I hope you have a great day
> ^D
["hello","world!","I","hope","you","have","a","great","day"]
The interact function takes a function of type ByteString -> ByteString as its argument. The entire input from the standard input device is passed to this function as its argument, and the resulting string is output on the standard output device.
Runs a command using the shell, and returns Handles that may be used to communicate with the process via its stdin, stdout, and stderr respectively.
Runs a raw command, and returns Handles that may be used to communicate with the process via its stdin, stdout and stderr respectively. For example, to start a process and feed a string to its stdin:
(inp,out,err,pid) <- runInteractiveProcess "..."
forkIO (hPutStr inp str)
runInteractiveProcess blocks signals around the fork(). Since blocking/unblocking of signals is a global state operation, we need to ensure mutual exclusion of calls to runInteractiveProcess. This lock is exported so that other libraries which also need to fork() (and also need to make the same global state changes) can protect their changes with the same lock. See https://github.com/haskell/process/pull/154.
ghci / ghc --interactive