streamly-process-0.3.0: Use OS processes as stream transformation functions
Copyright(c) 2022 Composewell Technologies
LicenseApache-2.0
Maintainerstreamly@composewell.com
Stabilityexperimental
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell2010

Streamly.Internal.System.Command

Description

 
Synopsis

Generation

toBytes :: (MonadAsync m, MonadCatch m) => String -> Stream m Word8 Source #

>>> toBytes = streamWith Process.toBytes
>>> toBytes "echo hello world" & Stdio.putBytes
hello world
>>> toBytes "echo hello\\ world" & Stdio.putBytes
hello world
>>> toBytes "echo 'hello world'" & Stdio.putBytes
hello world
>>> toBytes "echo \"hello world\"" & Stdio.putBytes
hello world

Pre-release

toChunks :: (MonadAsync m, MonadCatch m) => String -> Stream m (Array Word8) Source #

>>> toChunks = streamWith Process.toChunks
>>> toChunks "echo hello world" & Stdio.putChunks
hello world

Pre-release

toChars :: (MonadAsync m, MonadCatch m) => String -> Stream m Char Source #

>>> toChars = streamWith Process.toChars
>>> toChars "echo hello world" & Stdio.putChars
hello world

Pre-release

toLines Source #

Arguments

:: (MonadAsync m, MonadCatch m) 
=> Fold m Char a 
-> String

Command

-> Stream m a

Output Stream

>>> toLines f = streamWith (Process.toLines f)
>>> toLines Fold.toList "echo -e hello\\\\nworld" & Stream.fold Fold.toList
["hello","world"]

Pre-release

Effects

toString Source #

Arguments

:: (MonadAsync m, MonadCatch m) 
=> String

Command

-> m String 
>>> toString = runWith Process.toString
>>> toString "echo hello world"
"hello world\n"

Pre-release

toStdout Source #

Arguments

:: (MonadAsync m, MonadCatch m) 
=> String

Command

-> m () 
>>> toStdout = runWith Process.toStdout
>>> toStdout "echo hello world"
hello world

Pre-release

toNull Source #

Arguments

:: (MonadAsync m, MonadCatch m) 
=> String

Command

-> m () 
>>> toNull = runWith Process.toNull
>>> toNull "echo hello world"

Pre-release

Transformation

pipeBytes :: (MonadAsync m, MonadCatch m) => String -> Stream m Word8 -> Stream m Word8 Source #

Like pipeChunks except that it works on a stream of bytes instead of a stream of chunks.

>>> :{
   toBytes "echo hello world"
 & pipeBytes "tr [a-z] [A-Z]"
 & Stdio.putBytes
 :}
HELLO WORLD

Pre-release

pipeChars :: (MonadAsync m, MonadCatch m) => String -> Stream m Char -> Stream m Char Source #

Like pipeChunks except that it works on a stream of chars instead of a stream of chunks.

>>> :{
   toChars "echo hello world"
 & pipeChars "tr [a-z] [A-Z]"
 & Stdio.putChars
 :}
HELLO WORLD

Pre-release

pipeChunks :: (MonadAsync m, MonadCatch m) => String -> Stream m (Array Word8) -> Stream m (Array Word8) Source #

pipeChunks command input runs the executable with arguments specified by command and supplying input stream as its standard input. Returns the standard output of the executable as a stream of byte arrays.

If only the name of an executable file is specified instead of its path then the file name is searched in the directories specified by the PATH environment variable.

If the input stream throws an exception or if the output stream is garbage collected before it could finish then the process is terminated with SIGTERM.

If the process terminates with a non-zero exit code then a ProcessFailure exception is raised.

The following code is equivalent to the shell command echo "hello world" | tr [a-z] [A-Z]:

>>> :{
   toChunks "echo hello world"
 & pipeChunks "tr [a-z] [A-Z]"
 & Stdio.putChunks
 :}
HELLO WORLD

Pre-release

Helpers

runWith :: MonadCatch m => (FilePath -> [String] -> m a) -> String -> m a Source #

A modifier for process running APIs in Streamly.System.Process to run command strings.

For example:

>>> runWith Process.toString "echo hello"
"hello\n"
>>> runWith Process.toStdout "echo hello"
hello

Internal

streamWith :: MonadCatch m => (FilePath -> [String] -> Stream m a) -> String -> Stream m a Source #

A modifier for stream generation APIs in Streamly.System.Process to generate streams from command strings.

For example:

>>> streamWith Process.toBytes "echo hello" & Stdio.putBytes
hello
>>> streamWith Process.toChunks "echo hello" & Stdio.putChunks
hello

Internal

pipeWith :: MonadCatch m => (FilePath -> [String] -> Stream m a -> Stream m b) -> String -> Stream m a -> Stream m b Source #

A modifier for process piping APIs in Streamly.System.Process to pipe data through processes specified by command strings.

For example:

>>> :{
   toChunks "echo hello"
 & pipeWith Process.pipeChunks "tr [a-z] [A-Z]"
 & Stdio.putChunks
 :}
HELLO

Internal