首页 > 解决方案 > 如何从脚本在 iex 中运行命令?

问题描述

我正在尝试编写一个简单的脚本来启动 IEX 的不同节点,每个节点都有它的名称,并希望这些节点执行 de Node.ping :node_name@hostname 但我没有找到任何东西。

这是我目前拥有的脚本:

#!/bin/bash

#Opens 3 clients

gnome-terminal  --command="bash -c 'iex --sname client1; $SHELL'"
gnome-terminal  --command="bash -c 'iex --sname client2; $SHELL'"
gnome-terminal  --command="bash -c 'iex --sname client3; $SHELL'"

#Opens de server
gnome-terminal  --command="bash -c 'iex --sname server; $SHELL'"

标签: bashshellelixir

解决方案


不能iex以任何其他方式“管道”命令或将其发送到正在运行的实例,但幸运的是,人们可能会利用使用.iex.exs文件。

创建一个目录,.iex.exs在其中创建一个包含您想要的任何内容的目录,然后在其中运行您的脚本。


请注意,需要先调用Node.connect/1才能Node.ping/1成功。


推荐阅读