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

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews