Skip to content

Latest commit

 

History

History
40 lines (26 loc) · 1.09 KB

attaching_to_a_node.livemd

File metadata and controls

40 lines (26 loc) · 1.09 KB

Attaching to Another Node from Livebook

Starting a Node

In the terminal on your machine, start a node named terminal with the cookie secret.

iex --name terminal@localhost --cookie secret

Still in the terminal, register the group leader:

{:group_leader, pid} = Process.info(self(), :group_leader)
Process.register(pid, Terminal.GroupLeader)

Now, click on the "Runtime Settings" button on the left-hand side, and enter an Attached Node with the name and cookie from the step above. Next, let's get the PID of terminal's group leader:

pid = Process.whereis(Terminal.GroupLeader)

Finally, let's show some text in the terminal by sending a message to the group leader!

IO.puts(pid, "I'm sending a message from Livebook to the terminal!")

You should see the message show up in your terminal. Pretty cool! We can also list the files in the directory that the iex session was started from:

File.ls!()