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).
问问题
2186 次
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
于 2013-03-30T07:14:32.863 回答