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

Python3 os.popen() Method

Python3 os.popen() Method

Python3 OS File/Directory Methods Python3 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/python3

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

Python3 OS File/Directory Methods Python3 OS File/Directory Methods