Stream I/O to a java applet (os.popen?)

Michael Torrie torriem at gmail.com
Thu May 1 13:10:57 EDT 2008


Cody Woolaver wrote:
> This is all done at the terminal though and i need to have it done through a python file. I'm aware that i will have to use os.popen but am unfamiliar with how it works.

You'll probably want to look at the subprocess module, which replaces
the old os.popen stuff.  It's also a bit better at running on Windows.
There are lots of docs and examples relating to subprocess.  Probably
some good recipes too, especially for running on windows.  I'd begin by
looking on google for "python subprocess example windows."

Bear in mind interactive control of a subprocess is sometimes fraught
with difficulty, as it's easy to deadlock if you're waiting for the
subprocess to say something and it's waiting for you to say something.

On another track, you might want to consider using Jython, as it will
allow your python class file to interact directly with the Java stuff,
rather than having to do it via pipes and subprocesses.  The only
downside to Jython currently is it's stuck at Python 2.2 stuff.  But
it's a nice integration of Java and Python.



More information about the Python-list mailing list