RobertS

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

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

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 :+1:

Last Post!

Tuxified

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 :+1:

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement