2006/6/9, Bernard Lebel <[EMAIL PROTECTED]>:
Hi,
I'd like to know what are the differences at the various os.popenX
flavors. I read the documentation and I can see they return file
objects..... so what can you do with these file objects? I mean, why
would you need a set of file objects rather than another?
Sorry the difference is very not clear to me.
Thanks
Bernard
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Hello,
The common idea behind the various popen implementation is to provide the creation of pipes.A pipe is a flavor of a file object.A pipe serves the job to address data from a process to another,but what if sometimes you want to execute a command
out of the parent process on a child process?You should be able to issue the command,catch the result and even to know which way the thing has ended,at times.
If you are familiar with the concept of 'streams',the "input","output" and "error" stream are the resource of communication provided by Unix to handle these tasks,respectively.Nevertheless ,at times you don't need to gather data from all the streams,but just to control two of them out of three,for example.The reason could be that of sparing system resources,time or just that you don't need or want to.popen2 ,popen3 and popen4 are designed to catch exactly the streams you want to control.So:
popen2:
returns the file objects corresponding to the child stdin and stdout;
popen3:
returns the file objects corresponding to the child stdin,stdout and stderr;
popen4:
returns the file objects corresponding to the child stdout and stderr ( together as a single object) and stdin.
The file objects,you see,are what you normally make use to manipulate data within processes.
They are memory structures which assume peculiar names based on their type : Queues,Semaphores,Pipes and so on...
And they can persist a) in the scope of a process b) of a machine session c) on the filesystem (the strongest kind of persistence).
Choosing the right one for each task a matter depending on what you want to do with them.
I recognize I'm not being exhaustive but hope that helps.
Cheers,
Ivan
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor