, IPC . ( Qaru!) , , , , - , Erlang/Elixir Python, Python Erlang/Elixir. ( , Erlang Elixir, Python), ! Badu , Elixir Port .
, , , , . , , Erlang Python!
-, Python (eip.py):
from subprocess import Popen, PIPE
erl = Popen(['escript', 'eip.escript'],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
ping = input('Ping: ')
outs, errs = erl.communicate(input=ping.encode('utf-8'),
timeout=15)
print(outs.decode('utf-8'))
Erlang ( Python) - escript, , eip.escript:
#!/usr/bin/env escript
main(_Args) ->
Ping = io:get_line(""),
io:format("Pong: ~ts", [Ping]).
, python3 eip.py asdf Ping:, Pong: asdf.
Elixir : Mix , Mix escript. , :
$ mix new eip
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/eip.ex
* creating test
* creating test/test_helper.exs
* creating test/eip_test.exs
Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:
cd eip
mix test
Run "mix help" for more commands.
(, Mix , , - , )
escript mix.exs, :
defmodule Eip.MixProject do
use Mix.Project
def project, do: [
app: :eip,
version: "0.1.0",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
deps: deps(),
escript: escript()
]
def application, do: [extra_applications: [:logger]]
defp deps, do: []
defp escript, do: [main_module: Eip]
end
, , lib/eip.ex:
defmodule Eip do
def main(_argv) do
ping = IO.gets("")
IO.puts("Pong: #{ping}")
end
end
:
$ mix escript.build
Compiling 1 file (.ex)
Generated eip app
Generated escript eip with MIX_ENV=dev
eip.py , Elixirified ping/pong IPC thingamabob:
from subprocess import Popen, PIPE, TimeoutExpired
erl = Popen(['escript', 'eip/eip'],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
ping = input('Ping: ')
outs, errs = erl.communicate(input=ping.encode('utf-8'))
print(outs.decode('utf-8'))
, :
$ python3 eip.py
Ping: asdf
Pong: eof
, Erlang (.. IO.gets("") :io.get_line("") IO.puts("Pong: #{ping}") :io.fwrite("Pong: ~ts", [ping]), - Elixir STDIN , , . , , !