Python script interacting with Elixir command line into my project

Hi everyone, I am very new in elixir programming and currently I am in life and death situation.
phase 1: I implemented a python script for object detection in machine learning which is generating results are expected.
phase 2: I also setup a elixir and elixir ports to interact with ML python script via the command line which is also successful.
phase 3. trouble! my project is on python GUI not phoenix, how can I use python subprocess to allow my app to interact with the elixir shell. if that’s not possible what other way is available.

What is your exact requirement though? It’s not very clear. What do you want to achieve, sending the recognised objects to an Elixir CLI app?

Thank you so much for the respond
I want to make the following calls from my app to elixir instead of the commandline using python subprocess

1. iex

2. iex> port = Port.open({:spawn, "python3 detect.py"}, [:binary, :nouse_stdio, {:packet, 4}])

3. iex> id = :crypto.strong_rand_bytes(16)

4. iex> image = File.read!("dog.jpg")

5. iex> Port.command(port, [id, image])

6. 

	receive do
	{^port, {:data, <<image_id::binary-size(16), json_string::binary()>>}} -> 
	{image_id, json_string}
	end

for example
cmd=“port = Port.open({:spawn, ‘python3 detect.py’}, [:binary, {:packet, 4}])”
two = subprocess.Popen([cmd], stdout = inside)

So you want to call a Python program from Elixir and use its result – which is a file. Is that correct?

Yes! I want to use ML pythonscript1.py from elixir successfully and now I want use its result in my app which is also another pythonscript2.py

Sounds pretty complex though. Maybe all scripts should just post results in a shared database?

1 Like

By the way, welcome to Elixir Forum @janneh. :slight_smile: