Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python os.popen() method

Python os.popen() method

Python File methods Python OS file/directory methods


Overview

The os.popen() method opens a pipe from a command.

Valid on Unix and Windows

Syntax

The **popen()** method syntax is as follows:



os.popen(command[, mode[, bufsize]])

Parameters

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



# Use 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 File methods Python OS file/directory methods