Skip to content

Commit

Permalink
Update docs and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-akya committed Jul 8, 2024
1 parent 97d4b32 commit b685a31
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
26 changes: 21 additions & 5 deletions lib/exile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,26 @@ defmodule Exile do
"X 250 X\n"
```
With stderr set to :redirect_to_stdout
```
iex> Exile.stream!(["sh", "-c", "echo foo; echo bar >> /dev/stderr"], stderr: :redirect_to_stdout)
...> |> Enum.into("")
"foo\nbar\n"
```
With stderr set to :consume
```
iex> Exile.stream!(["sh", "-c", "echo foo\necho bar >> /dev/stderr"], stderr: :consume)
iex> Exile.stream!(["sh", "-c", "echo foo; echo bar >> /dev/stderr"], stderr: :consume)
...> |> Enum.to_list()
[{:stdout, "foo\n"}, {:stderr, "bar\n"}]
```
With stderr set to :disable
```
iex> Exile.stream!(["sh", "-c", "echo foo\necho bar >> /dev/stderr"], stderr: :disable)
iex> Exile.stream!(["sh", "-c", "echo foo; echo bar >> /dev/stderr"], stderr: :disable)
...> |> Enum.to_list()
["foo\n"]
```
Expand Down Expand Up @@ -195,7 +203,7 @@ defmodule Exile do
Chunk size can be less than the `max_chunk_size` depending on the amount of
data available to be read. Defaults to `65_535`
* `stderr` - different ways to handle stderr stream. possible values `:console`, `:disable`, `:stream`.
* `stderr` - different ways to handle stderr stream. possible values `:console`, `:redirect_to_stdout`, `:disable`, `:stream`.
1. `:console` - stderr output is redirected to console (Default)
2. `:redirect_to_stdout` - stderr output is redirected to stdout
3. `:disable` - stderr output is redirected `/dev/null` suppressing all output
Expand All @@ -222,6 +230,14 @@ defmodule Exile do
|> Stream.run()
```
Stream with stderr redirected to stdout
```
Exile.stream!(["sh", "-c", "echo foo; echo bar >> /dev/stderr"], stderr: :redirect_to_stdout)
|> Stream.map(&IO.write/1)
|> Stream.run()
```
Stream with stderr
```
Expand Down Expand Up @@ -258,7 +274,7 @@ defmodule Exile do
@spec stream!(nonempty_list(String.t()),
input: Enum.t() | collectable_func(),
exit_timeout: timeout(),
stderr: :console | :disable | :consume,
stderr: :console | :redirect_to_stdout | :disable | :consume,
ignore_epipe: boolean(),
max_chunk_size: pos_integer()
) :: Exile.Stream.t()
Expand All @@ -279,7 +295,7 @@ defmodule Exile do
@spec stream(nonempty_list(String.t()),
input: Enum.t() | collectable_func(),
exit_timeout: timeout(),
stderr: :console | :disable | :consume,
stderr: :console | :redirect_to_stdout | :disable | :consume,
ignore_epipe: boolean(),
max_chunk_size: pos_integer()
) :: Exile.Stream.t()
Expand Down
13 changes: 7 additions & 6 deletions lib/exile/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ defmodule Exile.Process do
Pipe owner can read or write date to the owned pipe. `:stderr` by
default is connected to console, data written to stderr will appear on
the console. You can enable reading stderr by passing `stderr: :consume`
during process creation.
the console.
Special function `Exile.Process.read_any/2` can be used to read
from either stdout or stderr whichever has the data available.
If you want to read stderr you have two options
* `:redirect_to_stdout`: stderr data will be redirected to stdout. This is similar to `:stderr_to_stdout` option present in [Ports](https://www.erlang.org/doc/apps/erts/erlang.html#open_port/2). With this option when you read stdout you will see both stdout & stderr combined and you won't be able differentiate streams separately
* `:consume`: stderr data can be consumed separately using `Exile.Process.read_stderr/2`. Special function `Exile.Process.read_any/2` can be used to read from either stdout or stderr whichever has the data available. See the examples for more details.
All Pipe operations blocks the caller to have blocking as natural
back-pressure and to make the API simple. This is an important
Expand Down Expand Up @@ -300,8 +302,7 @@ defmodule Exile.Process do
* `env` - a list of tuples containing environment key-value.
These can be accessed in the external program
* `stderr` - different ways to handle stderr stream.
possible values `:console`, `:disable`, `:stream`.
* `stderr` - different ways to handle stderr stream. Possible values `:console`, `:redirect_to_stdout`, `:disable`, `:stream`.
1. `:console` - stderr output is redirected to console (Default)
2. `:redirect_to_stdout` - stderr output is redirected to stdout
3. `:disable` - stderr output is redirected `/dev/null` suppressing all output
Expand Down

0 comments on commit b685a31

Please sign in to comment.