ex_cmd v0.2.0 ExCmd.Process View Source
Helper to interact with ExCmd.ProcessServer
Overview
Each ExCmd.ProcessServer
process maps to an instance of port (and
an OS process). Internally ExCmd.ProcessServer
creates and manages
separate processes for each of the IO streams (Stdin, Stdout,
Stderr) and a port that maps to an OS process of odu
. Blocking
functions such as read
and write
only blocks the calling
process, not the ExCmd.Process
itself. A blocking read does
not block a parallel write. Blocking calls are the primitives for
building back-pressure.
For most of the use-cases using ExCmd.stream!
abstraction should
be enough. Use this only if you need more control over the
life-cycle of IO streams and OS process.
Link to this section Summary
Functions
Waits for the program to terminate.
Closes input stream. Which signal EOF to the program
Opens the error stream of the program for reading. Blocks till writer opens
Opens the input stream of the program for writing. Blocks till reader opens
Opens the output stream of the program for reading. Blocks till writer opens
Returns port_info
Return bytes written by the program to output stream.
Return bytes written by the program to error stream.
Opens the port and runs the program
Returns status of the process. It will be either of :started
, {:done, exit_status}
Kills the program
Writes iodata data
to programs input streams
Link to this section Functions
Waits for the program to terminate.
If the program terminates before timeout, it returns {:ok, exit_status}
else returns :timeout
Closes input stream. Which signal EOF to the program
Opens the error stream of the program for reading. Blocks till writer opens
Opens the input stream of the program for writing. Blocks till reader opens
Opens the output stream of the program for reading. Blocks till writer opens
Returns port_info
read(server, timeout \\ :infinity)
View Sourceread(pid(), non_neg_integer() | :infinity) :: {:ok, iodata()} | :eof | {:error, String.t()} | :closed
Return bytes written by the program to output stream.
This blocks until the programs write and flush the output
read_error(server, timeout \\ :infinity)
View Sourceread_error(pid(), non_neg_integer() | :infinity) :: {:ok, iodata()} | :eof | {:error, String.t()} | :closed
Return bytes written by the program to error stream.
This blocks until the programs write and flush the output
Opens the port and runs the program
Starts ExCmd.ProcessServer
Starts a process for running cmd
with arguments args
with options opts
. Note that this does not run the program immediately. User has to explicitly run by calling run/1
, open_input/1
, open_output/1
depending on the program.
By default, ExCmd assumes that the command uses both stdin and stdout. So both streams (Enumerable and Collectable) must be used even if the command does not use it. You can change this behaviour by passing no_stdin
option for commands which does not read input fron stdin (such as find
command). see ExCmd.Process
options for more detils.
Options
no_stdin
- If set to true, User does not need to use collectable stream. ExCmd assumes that the command does not read input from stdin. Defaults tofalse
no_stderr
- Whether to allow reading from stderr. Note that settingtrue
but not reading from stderr might block external program due to back-pressure. Defaults totrue
log
- When set totrue
odu outputs are logged. Defaults tofalse
Returns status of the process. It will be either of :started
, {:done, exit_status}
Kills the program
write(server, data, timeout \\ :infinity)
View Sourcewrite(pid(), iodata(), non_neg_integer() | :infinity) :: :ok | {:error, String.t()} | :closed
Writes iodata data
to programs input streams
This blocks when the fifo is full