0

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?

4
  • What mechanism is used to run the python program now? Commented Jan 14, 2014 at 1:22
  • the google term you are looking for is "message passing interface" Commented Jan 14, 2014 at 1:22
  • I'm guessing Process Commented Jan 14, 2014 at 1:22
  • @JoranBeasley thanks for the terminology tip! Commented Jan 14, 2014 at 1:33

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.