Os Popen
# Python2.x Python os.popen() Method
[ Python OS File/Directory Methods](#)
* * *
### Overview
The os.popen() method is used to open a pipe from a command.
Valid on Unix and Windows.
### Syntax
The **popen()** method syntax is as follows:
os.popen(command[, mode[, bufsize]])
### Parameters
* **command** -- The command to be used.
* **mode** -- The mode can be 'r' (default) or 'w'.
* **bufsize** -- Specifies the buffer size needed for the file: 0 means unbuffered; 1 means line buffered; other positive values indicate a buffer of approximately the given size in bytes. Negative bufsize means using the system default, which is typically line buffered for tty devices and fully buffered for other files. If this parameter is omitted, the system default is used.
### Return Value
Returns an open file object with file descriptor fd.
### Example
The following example demonstrates the use of the popen() method:
#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # Using mkdir command a = 'mkdir nwdir' b = os.popen(a,'r',1)print b
The output of the above program is:
open file 'mkdir nwdir', mode 'r' at 0x81614d0
[ Python OS File/Directory Methods](#)
YouTip