RobertS
Elixir EScript pass echo to script
Hey, I am trying to set up an elixir escript for a simple script.
I want to pass a result from echo using Linux pipe.
Here is an example:
echo -e '1234' | ./script argument
However in main script function:
def main(args) do
IO.inspect(args)
end
when inspecting args I see only:
["argument"] instead of ["1234", "argument"]
Would appreciate your help or any resources.
Marked As Solved
RobertS
I found it:
The pipe operator passes the data as stdin so you need to do IO.read(:stdio, :line) in main to read it.
Also Liked
Tuxified
IIRC linux pipes pass info to the next process via STDIN, so I think you need some function from IO module to read it, for example:
defmodule MyScript do
def main(args) do
IO.inspect(args, label: "Args")
Enum.each(IO.stream(:stdio, :line), &IO.write("stdio: #{&1}"))
end
end
[edit]
You found the anwser while I was looking at Elixir docs ![]()
Last Post!
Tuxified
IIRC linux pipes pass info to the next process via STDIN, so I think you need some function from IO module to read it, for example:
defmodule MyScript do
def main(args) do
IO.inspect(args, label: "Args")
Enum.each(IO.stream(:stdio, :line), &IO.write("stdio: #{&1}"))
end
end
[edit]
You found the anwser while I was looking at Elixir docs ![]()
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
- #code-sync
- #javascript
- #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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









