1

So I've looked a bit into the subprocess library, and I think that it is the right library to use, but I can't seem to find out how one would go about passing input to the program during runtime. I want to run a jar using a python script and analyze the output of that jar file while it is running (for an indefinite amount of time). Then, based on that output, I want to be able to pass back input to the jar file (which is accepting input).

1 Answer 1

1

You will need to use the subprocess.Popen constructor, passing as stdin and stdout arguments either:

  • a file-like object of your choice, which you can then read and write in a loop during the program execution
  • the special value subprocess.PIPE, which allows then to access these streams through the returned Popen object as properties stdin and stdout. Liek the first case, you'll need to run a loop reading from stdout and writing to stdin.

There are some nice examples at http://sharats.me/the-ever-useful-and-neat-subprocess-module.html

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.