ijverig

ijverig

How could I send an EOF/EOT inside an input in iex?

Say inside

iex> IO.read :all

Usually we do it by pressing ctrl+D on other shells, but that’s something else in Erlang.

If there isn’t a way, how could I stop the input in a way that I could access the data already entered?

Showing Posts 1 to 6

scarfacedeb

scarfacedeb

You can use Ctrl + G to enter Job control mode, there you can interrupt the running job (e.g. with i 1) and connect to it back.

iex(5)>  IO.read :all
1111

User switch command
 --> j
   1* {erlang,apply,[#Fun<Elixir.IEx.CLI.1.121285560>,[]]}
 --> i 1
 --> c 1
{:error, :interrupted}
iex(6)>

ijverig

ijverig OP

Thanks!
But this way I do not get the input.

I hope there’s a way of transmitting EOT or EOF.

scarfacedeb

scarfacedeb

I’m unable to find any info on how to send EOF manually, so I’d guess that the next best thing is to use custom string to terminate the input.

defmodule A do
   def read(acc \\ "") do
     case IO.read(:stdio, :line) do
       "eof\n" -> acc
       line -> read(acc <> line)
     end
   end
end

iex(11)> A.read
1 line
2 line
eof
"1 line\n2 line\n"
iex(12)>
scarfacedeb

scarfacedeb

You can also just use IO.gets, if you’re only interested in the first line.

scarfacedeb

scarfacedeb

Another way to write it:

IO.stream(:stdio, :line) |> Stream.take_while(&(&1 != "EOF\n")) |> Enum.reduce("", &(&2 <> &1))
jstimps

jstimps

It appears erl and iex both block the user from issuing the EOF signal, which can usually be done with Ctrl+d.

However, if you use elixir then it works!

$ elixir --eval 'IO.write("> "); l = IO.read(:stdio, :line); IO.inspect(l)'
> :eof

At the prompt above, I gave Ctrl+d and it got :eof like expected. However, this doesn’t work in iex; I assume this is on purpose to avoid accidentally terminating the shell input loop.

Hope this helps other future searchers :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
mnkhod
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews