Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data from Python program to Java program

I have a Python program status.py that prints some status updates (strings) to the console. However, I need to write a JavaFX program Display.java that launches the Python program and then prints the Python program's status updates to a TextArea.

To accomplish this I've altered status.py to write its status updates to a text file and then have the Java program read the text file into the TextArea.

The text file method is working, but I feel like there is a better way to communicate. I am thinking about having the Python program write its status updates to a socket and having the Java program listen to the socket using ServerSocket.

Is using a networking approach such as communicating through sockets the best way to accomplish communication between status.py and Display.java? If not, what is the best way to accomplish such inter-proccess communication?

like image 240
jshapy8 Avatar asked Feb 11 '26 22:02

jshapy8


1 Answers

There are two options for communicating information from a Python process to a Java process:

  1. Java's popular networking libraries will make it easy to read in data through a socket. Since you can easily open up a socket in Python, implementing socket communication would be the easiest solution.
  2. If you have experience with Jython, you can eliminate the need to perform inter-process communication by including the Python code within the Java code.
like image 59
jshapy8 Avatar answered Feb 14 '26 15:02

jshapy8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!