[Tutor] Re: communication between java and python?

Jeff Shannon jeff at ccvcorp.com
Fri Jan 14 03:33:51 CET 2005


Lee Harr wrote:

>> I'm trying to communicate between Python and Java and using
>> os.popen(). But thing dont work...The Java program reads strings from
>> stdin and the python program just writes to stdout.
>>
>> [...]
> 
> """
> popen(command[, mode[, bufsize]])
> Open a pipe to or from command. The return value is an open file
> object connected to the pipe, which can be read or written
> depending on whether mode is 'r' (default) or 'w'.
> """
> 
> So, I do not believe that you can both write to and read from
> a file handle opened with popen.

Not only that, but access to the file-like pipe objects is probably 
buffered.  You'll want to call pipe.flush() after writing to it, or 
the child process won't actually see what you've written.

Jeff Shannon
Technician/Programmer
Credit International




More information about the Tutor mailing list