Python method popen() opens 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 the mode is 'r' (default) or 'w'.The bufsize argument has the same meaning as in the open() function.
Following is the syntax for popen() method:
os.popen(command[, mode[, bufsize]])
This method returns an open file object connected to the pipe.
The following example shows the usage of popen() method.
# !/usr/bin/python import os, sys # using command mkdir a = 'mkdir nwdir' b = os.popen(a,'r',1) print b
When we run the above program, it produces the following result:
open file 'mkdir nwdir', mode 'r' at 0x81614d0
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.