Cannot interact with terminal spawned by port

I am trying to create a Bakeware CLI tool that takes list of servers, opens a terminal for each server, and runs the appropriate ssh command in each. I can then interact with them as needed. However, I cannot get the terminals to execute commands.

Let’s take a simple case:

iex(1)> port ={:spawn, "urxvt"}, [:binary])

spawns an Elixir process, which spawns an OS process (Linux), which spawns a child process running a terminal program (unicode rxvt). This works, it creates a terminal window.

Since a child process inherits stdin, stdout, and stderr from its parent,

iex(2)> send(port, {self(), {:command, "echo Hello"}})

should send “echo Hello” to stdin of the OS process, which, in turn, should send it to the child process stdin. However, it does not.

How can I open a terminal window and send commands to it?

Thanks! :smiley:


You are misunderstanding what part of the application receives messages. Sending commands to urxvt will send messages to STDIN of terminal emulator, not process running within that terminal. If you want to communicate with process within terminal, then you need to check out documentation of terminal you use. Alternatively do everything within single process.

1 Like