ForeverConfused
ForeverConfused

Reputation: 1777

spawn get_line for stdin and have it work?

how do I get this to work

spawn(fun() -> io:get_line("Prompt>") end).

to where it would work as if it didn't have the spawn. I tried standard_io and group_leader() but doesn't make difference.

Upvotes: 2

Views: 372

Answers (1)

Lukas
Lukas

Reputation: 5327

Try

spawn(fun() -> timer:sleep(100),io:get_line("Prompt>") end).

What you see is a race condition between shell and your spawn/1. Generally when doing anything with io:get_line I would advice using 'erl -noshell -s Mod Fun' to start the program as that makes this issue go away.

Upvotes: 4

Related Questions