jshapy8
jshapy8

Reputation: 2051

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?

Upvotes: 3

Views: 3177

Answers (1)

jshapy8
jshapy8

Reputation: 2051

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.

Upvotes: 1

Related Questions