sribe
System.cmd output in a stream
Is there a fairly direct way to get from System.cmd a stream which when enumerated will return the command output line by line?
:into IO.stream()
Just echos output to stdout as it comes in. It seems that I can get what I need by either creating a process to receive output and using receive there, or dropping down to Erlang and using a port directly. But I’m wondering if there is some higher-level support for this which I am missing?
Most Liked
fuelen
:into parameter accepts Collectable.t(), so you can use an empty list:
> System.shell("echo hello; sleep 1; echo world; sleep 1; echo end;", into: [])
{["hello\n", "world\n", "end\n"], 0}
or create a custom struct and implement Collectable protocol for it.
c4710n
As far as I know, there’s no more higher-level abstractions in Elixir itself.
You have to:
- use
Portdirectly - or, some external packages, like porcelain
Personally, I prefer using Port directly, you can get more examples at:
I’m not sure about the context of your requirements. But personally, I always lean towards small and sufficient implementations rather than large and comprehensive ones. From that perspective, a simple
Portwrapper is sufficient.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








