cjen07
Is there a way to call python using ports, and get the result by receive block?
Example code is preferred, thanks in advance.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 15 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
micahrye
Thanks @NobbZ, @sasajuric, @OvermindDL1, community always rooks!
OvermindDL1
Big Endianness is default on TCP I/O traffic, and since the BEAM is optimized and designed for I/O then that is why it defaults to that.
micahrye
Yes you are correct, earlier I had made the mistake to use
struct.pack("i", 4)in python which returned byte representation inlittle-endian(my native), but Elixir defaults tobig-endian, which I never knewAdd that to the fact I do not really know Ruby and did not realize, or read closely, that [msg.bytesize].pack(“N”) encodes as an unsigned big-endian integer and I floated off into the confused.
sasajuric
Here’s the simplest example I can think of which works on my machine:
micahrye
I will give it more looking.
NobbZ
I’m really wondering why this works, as the message format you use in in python and node is plain wrong.
To debug this, you should consider also using
stderr_to_stdoutandexit_statusoptions when opening the port.micahrye
I will update more later, but I seem to have found the issue. Above I had been creating the command as
python <path_to_script>where the path was the absolute path.When I changed the cmd to
python ./src/py_port_test.pyI get the response as i would expect.I still do not understand why the absolute path matters for Python and Node, but not Ruby. I will look a bit more later.
NobbZ
{:packet, 4}means, that you need 4 bytes denoting the lenght of the message and no newline after that (unless its part of the message).In elixir syntax the message has to look like this:
micahrye
I am not understanding something about ports, and it could be that I do not understand Python and NodeJS.
First my setup:
Mac OSX
Elixir 1.8.1
Erlang 21
Python 3.7.2, also tried 2.7.2.
In addition I have read Outside Elixir too.
I wanted to communicate with a python script via an Elixir port. For learning, I wanted to do this directly rather than using some other library, e.g. ErlPort. After some head banging I am here
In Ruby, Python, and Node I have a very simple script that only prints out to stdout
Ruby
Python
Node
From Elixir repl I am running
Where “cmd” is something like:
and the like for Ruby and Node.
Now when I do that for the Ruby script and the run
flush()I get the following:Where “asdf” is the expected data.
For Python and Node I get:
As you can see there is no {:data, “asdf”} msg as I would expect when writing to stdout from python (similar for node).
I have tried a lot of variations on writing to stdout/stderr etc. to no effect.
cjen07
Sure, I will write a script.