Explanation? Uh-oh...
Here is where I expose my lack of understanding:
Code:
proc=Popen('pwd', shell=True, stdout=PIPE)
This makes proc an instance of the Popen class.
This line, as I understand it, sets up a subshell which runs the 'pwd' command.
The stdout file handle is directed to PIPE. If you don't do this, then the subshell prints its output to the terminal. By directing it to the PIPE, you can then read what has been sent to the PIPE via the command
proc.communicate() returns a 2-tuple: (stdout, stderr)
So
Code:
output=proc.communicate()[0]
picks of the stdout, and ignores stderr.
Hope this helps. I'm sure Doug Hellmann explains it better.
PS. The official documentation on the subprocess module can be found here:
http://docs.python.org/library/subpr...ule-subprocess
Bookmarks