Question

Lets say I have a java program which is running something. And then I run a python program, from java, what is the fastest way to give input back to java? I know that Jython can do what I am describing in a better way, but for the actual application I am working on I would rather not use Jython, if I can avoid it. Note: I have a text file based system working. I'm just curious if there is a faster way?

Was it helpful?

Solution

Assuming you are starting the python program something like this:

Process p = Runtime.exec("python", pathToProgram);

then you can just print stuff from Python. You can get it by this:

BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));

Now, to get back a line of output, you can do this:

String line = in.readLine();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top