Goose97

Goose97

How to stop Erlang VM from polling stdin?

I’m developing a terminal UI application. The structure of the application is like so:

  • Core logic is handled by Elixir
  • Interacting with the terminal (draw, reading events,…) is handled via a NIF

The NIF reads from stdin and translates into keyboard events. The problem is the Erlang VM seems to also reads from stdin, stealing the input from the NIF. Here’s the dtruss output (dtrace wrapper) when running a simple Elixir script with mix run (just enable terminal raw mode and sleep):

select(0x16, 0x1496041B8, 0x0, 0x149604238, 0x16D76ABB8)		 = 1 0

              libsystem_kernel.dylib`__select+0x8
              beam.smp`erts_schedule+0x39bc
              0x143885be0
              0x1439047d8

read(0x0, "b\0", 0x10000)		 = 1 0

              libsystem_kernel.dylib`read+0x8
              beam.smp`erts_port_task_execute+0x980
              beam.smp`erts_schedule+0x3030
              0x143885be0
              0x1439047d8

My theory is that there a separated thread in the VM keep polling on a list of file descriptors (stdin included). The bytes is buffer somewhere and can be retrieved later on, for example IO.read(:stdio, 5).

Is this correct? If so, how can tell the VM to NOT read from the stdin?

Marked As Solved

nhpip

nhpip

I think you should try the Erlang flags -detached and/or -noshell / -noinput.

Take a look at Erlang erl

So:

elixir —erl “-noinput -detached “

Or something close

Also Liked

Goose97

Goose97

Thanks. -noinput does the trick.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

We're in Beta

About us Mission Statement