Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print a PID in Elixir?

Tags:

elixir

I tried to:

pid = spawn fn -> 1 + 2 end
IO.puts(pid)
IO.puts(IO.inspect(pid))

and both given a

** (Protocol.UndefinedError) protocol String.Chars not implemented for #PID<0.59.0>

There must be a way to get the "#PID<0.59.0>" representation of the pid, since the REPL prints that #PID<0.59.0>.

like image 281
RubenLaguna Avatar asked Mar 24 '16 12:03

RubenLaguna


1 Answers

When you want to append it to a string (to display some extra details), you can use string interpolation:

pid = spawn(fn -> 1 + 2 end)
IO.puts "Pid: #{inspect pid}"
like image 160
Nico Napoli Avatar answered Sep 16 '22 16:09

Nico Napoli