Facing issues during compile

Hi everybody! Im new in Elixir and i foun a problem that maybe someone can help me:
For learning proposes, I’m solving some exercise from Codeabby and I download the data and save it in a file to latter read it from stdin.
The command that Im using to read stdin is IO.read(:stdio, :line) and its working in a program like this:

defmodule Prueba do
    def main do
        name = IO.read(:stdio, :line)
        IO.puts name


and in terminal a run this: cat Data.txt | elixir prueba.exs

And it works. The problem is, to summit my solution, a pipeline tries to compile it, but when it sees the line Prueba.main, it starts the program and throws me an error. I Found this because I tray in IEX c(“program.exs”) and have the same error. it will be fixed if I delete Prueba.main, but it would execute when I type in the terminal cat Data.txt | elixir prueba.exs.
My question is… there’s a way to execute the program without the final line? or what do you think about this situation?

welcome to elixir. Elixir is a compiled language, and it will also evaluate code during compilation. To make a compiled executable out of a single file you may want to build a escript:


but… build a Escript it’s go too far no? I’m only searching for a way that i can excute the program without the final line… :pensive: :pensive:

The line Prueba.main its what makes the compile fail.

Do you control how the program is executed? If so, remove the line from the compilation code and then execute it as elixir -r path/to/file -e Prueba.main.


You are the best thing that could ever happen in my life!!! thanks a lot!!! :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: