pipes

Daniel Klein danielk at featherbrain.net
Tue Sep 11 10:07:27 EDT 2007


On Mon, 10 Sep 2007 20:15:40 -0700, yagyala <mbrown at phys.ksu.edu>
wrote:

>Hi. I'm rtying to use pipes to communicate between a python GUI and a
>spawned C++ program. I prefer not to use forking because the app may
>be run on windows, where forking isn't supported. Roughly what I'm
>doing is:
>
>(r,w) = os.pipe()
>spawnl(P_WAIT, 'tool.exe', ' ', message, str(w))
>close(w)
>print os.read(r, 1000)
>
>In c++ ,
>...
>int main(int argc, char** argv)
>{
>
>}

The 'subprocess' module provides an easier interface imo, eg:

process = subprocess.Popen('tool.exe', stdin=subprocess.PIPE,      
               stdout=subprocess.PIPE, universal_newlines=true)
(self.outstream, self.instream) = (process.stdout, process.stdin)

Daniel Klein



More information about the Python-list mailing list