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

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement