Hi everybody!
I have a problem trying to solve a challenge in Elixir.
I decided to solve my challenge using Elixir because I would like to learn something new while I’m facing these challenges. So… here’s my situation:
At my first attempt at MR some exercise I was reading the data directly from the file using the command File.read(“DATA.lst”). my merge request was close and I received a message that says “read data from stdin”. Ok… I’m a rookie in programming so I needed to google what does it means and I found that stdin is short for standard input , stdin is an input stream where data is sent to and read by a program and the way to use it in Elixir its the following:
- change File.read(“DATA.lst”) for IO.read(:stdio, :line)
- In terminal type cat(type) DATA.lst | elixir program.exs
Ok, here is where I need you to tell me if I’m wrong. but I will continue with other things that I saw. This way of executing an Elixir file is named running elixir file as a script and this is what it does:
- A BEAM instance is started
- The file prueba.exs is loaded and compiled in memory. The interpreted symbols are loaded into the VM.
- The code after the module, (i.e. Prueba.main) is interpreted and run.
- After completing the execution, the BEAM instance is shutdown.
You can read this on this page: https://thinkingelixir.com/2019-04-running-an-elixir-file-as-a-script/
So, to expose my problem(without show my solution jeje) I made the following program:
A simple hello world program that takes from stdin a string from a file to print a message, this is what I type in the terminal and the output:
So… It works!!!
. I try the same with my program and this was the output:
everything was so happy at this point. uwu
Ok I push to my branch my solution and the pipeline crush
and this was the error message:
I look at the message and I saw something odd, the function String.split is receiving :eof and, as it says in this page: https://hexdocs.pm/elixir/IO.html, :oef is returned when an empty string is passed from stdin(or well… that’s what I understood).
The error from the pipeline says that it was a compilation error, the same error I get when I use the IEX terminal and type the following command to compile:
- iex(1) > c(“rechavar.exs”)
So, i think that maybe, when it compiles, it reads the last line (Prueba.main in my example) and execute the program. that’s why I try to push it without the final line. And it works!!! but when I try to execute it in the terminal that’s what happens:
NOTHING!!!
At this point I really don’t know what to do… I solved the message that i received in the MR yesterday like in 20 min, but this problem doesn’t let me continue.
Hope you are having such a great day!