How can I print a PID in Elixir?
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}"
I found that I'm using the wrong inspect
, there is IO.inspect/2
and Kernel.inspect/2
. The second works for me:
pid = spawn fn -> 1 + 2 end
IO.puts(inspect(pid))
You don't need to wrap IO.inspect
in a call to IO.puts
. Simply calling IO.inspect
will do what you're looking for.
pid = spawn fn -> 1 + 2 end
IO.inspect(pid)