process-extras: Process extras

[ library, mit, system ] [ Propose Tags ]

Extends http://hackage.haskell.org/package/process. Read process input and output as ByteStrings or Text, or write your own ProcessOutput instance. Lazy process input and output. ProcessMaker class for more flexibility in the process creation API.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.2.0, 0.3.0, 0.3.0.1, 0.3.1, 0.3.3.1, 0.3.3.2, 0.3.3.3, 0.3.3.4, 0.3.3.5, 0.3.3.6, 0.3.3.7, 0.3.3.8, 0.3.4, 0.4, 0.4.1, 0.4.1.1, 0.4.1.3, 0.4.1.4, 0.7, 0.7.1, 0.7.2, 0.7.3, 0.7.4 (info)
Dependencies base (>=4.6 && <4.11), bytestring, deepseq (>=1.1 && <1.5), generic-deriving (>=1.10), ListLike (>=4), process, text [details]
License MIT
Author David Lazar, Bas van Dijk, David Fox
Maintainer David Fox <dsf@seereason.com>
Revised Revision 1 made by HerbertValerioRiedel at 2019-03-31T09:23:13Z
Category System
Home page https://github.com/seereason/process-extras
Source repo head: git clone https://github.com/seereason/process-extras
Uploaded by DavidFox at 2016-05-14T21:28:03Z
Distributions Arch:0.7.4, Debian:0.7.4, LTSHaskell:0.7.4, NixOS:0.7.4, Stackage:0.7.4
Reverse Dependencies 27 direct, 34 indirect [details]
Downloads 51559 total (193 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-05-14 [all 1 reports]

Readme for process-extras-0.4.1.1

[back to package description]

About

Extra functionality for the Process library.

  • Read process input and output as ByteStrings or Text, or write your own ProcessOutput instance.
  • Lazy process input and output (i.e. read output from processes that run forever.)
  • ProcessMaker class for more flexibility in the process creation API.

Contributing

This project is available on GitHub. You may contribute changes there.

Please report bugs and feature requests using the GitHub issue tracker.

Examples:

The output type of the raw system process functions is ByteString. Instances of ListLikeProcessIO are provided to read as type String, Text, Lazy Text, ByteString, or Lazy ByteString. Select by casting the result, or by specifying the module containing the specialized function:

> :m +System.Process.ListLike Data.ByteString Data.Text.Lazy
> readCreateProcessWithExitCode (shell "echo 'λ'") mempty :: IO (ExitCode, ByteString, ByteString)
(ExitSuccess,"\206\187\n","")
> readCreateProcessWithExitCode (shell "echo 'λ'") mempty :: IO (ExitCode, Text, Text)
(ExitSuccess,"\955\n","")
> readCreateProcessWithExitCode (shell "echo 'λ'") mempty :: IO (ExitCode, String, String)
(ExitSuccess,"\955\n","")
> System.Process.Text.readCreateProcessWithExitCode (shell "yes | head -10") mempty
(ExitSuccess,"y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n","")

Although the output type can be lazy, normal process functions still need to read until EOF on the process output before returing anything. If you have a process whose output never ends you can use the readCreateProcessLazy function to read it. Functions like readProcess would block waiting for EOF on the process output:

> (Prelude.take 4 <$> readCreateProcessLazy (proc "yes" []) mempty :: IO [Chunk Text]) >>= mapM_ (putStrLn . show)
ProcessHandle <process>
Stdout "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny ..."
...

The output type can be any instance of ProcessOutput, instances for types (ExitCode, a, a), [Chunk a], and (ExitCode, [Chunk a]) are provided. [Chunk a] can be converted to any other instance of ProcessOutput using collectOutput

> (readCreateProcess (shell "gzip -v < /proc/uptime") mempty :: IO [Chunk ByteString]) >>= mapM_ (putStrLn . show)
Stdout "\US\139\b\NUL\237\136\&7W\NUL\ETX345\183\&403\215\&31Q04267\177\&0\177\212\&33\225\STX\NUL_\169\142\178\ETB\NUL\NUL\NUL"
Stderr "gzip: stdin: file size changed while zipping\n -8.7%\n"
Result ExitSuccess
> (readCreateProcess (shell "uptime") mempty :: IO [Chunk ByteString]) >>= writeOutput
 14:00:34 up 18 days,  7:16,  6 users,  load average: 0.04, 0.10, 0.08
> collectOutput <$> (readCreateProcess (shell "gzip -v < /proc/uptime") mempty :: IO [Chunk ByteString]) :: IO (ExitCode, ByteString, ByteString)
(ExitSuccess,"\US\139\b\NUL\185\137\&7W\NUL\ETX345\183\&427\212\&33W0426731\177\208\&35\225\STX\NUL\237\192\CAN\224\ETB\NUL\NUL\NUL","gzip: stdin: file size changed while zipping\n -8.7%\n")
> collectOutput <$> (readCreateProcess (shell "gzip -v < /proc/uptime") mempty :: IO [Chunk ByteString]) :: IO (ExitCode, ByteString, ByteString)
(ExitSuccess,"\US\139\b\NUL\185\137\&7W\NUL\ETX345\183\&427\212\&33W0426731\177\208\&35\225\STX\NUL\237\192\CAN\224\ETB\NUL\NUL\NUL","gzip: stdin: file size changed while zipping\n -8.7%\n")
> (collectOutput . filter (\x -> case x of Stderr _ -> False; _ -> True)) <$> (readCreateProcess (shell "gzip -v < /proc/uptime") mempty :: IO [Chunk ByteString]) :: IO (ExitCode, ByteString, ByteString)
(ExitSuccess,"\US\139\b\NUL<\138\&7W\NUL\ETX345\183\&410\210\&3\176P04267713\213\&37\224\STX\NULT\142\EOT\165\ETB\NUL\NUL\NUL","")

Some cases that need investigation:

> (readCreateProcess (shell "gzip -v < /proc/uptime") mempty :: IO [Chunk String]) >>= mapM_ (putStrLn . show)
*** Exception: fd:13: hGetContents: invalid argument (invalid byte sequence)
> (readCreateProcess (shell "gzip -v < /proc/uptime") mempty :: IO [Chunk Text]) >>= mapM_ (putStrLn . show)
*** Exception: fd:13: hClose: invalid argument (Bad file descriptor)