Invoke External Application in Java
I recently had a scenario where part of what I wanted to do was in Java, and the other part was in an application that was written in Python. Rather than than rewrite my entire code base in one language or the other, I wanted to find a (quick and dirty) way to invoke the Python application from Java. One way to do this would be to use some type of service-oriented architecture (e.g. via an HTTP/XML Web service), but I didn’t want to get into that complexity for this simple task. Another way would be to use some type of interface like Jython.
Instead I just invoked the other program as if from the command line and retrieved the output that was stored in text files. This type of approach will probably only work in limited scenarios, but it can come in handy for integrating different programming languages.
This article gives a nice code sample (that has worked for me) that illustrates how to do this. If you’re like me, you’ll probably simplify the code, but at least it shows how to do it.
