YouTip LogoYouTip

Python3 Os Popen

# Python3.x Python3 os.popen() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The os.popen() method is used to open a pipe to or from a command. Valid on Unix and Windows. ### Syntax The syntax for the **popen()** method is as follows: os.popen(command[, mode[, bufsize]]) ### Parameters * **command** -- The command to be used. * **mode** -- The mode permission can be 'r' (default) or 'w'. * **bufsize** -- Specifies the buffering size required for the file: 0 means no buffering; 1 means line buffering; other positive values indicate a buffer of the specified size (approximate, in bytes). A negative bufsize means using the system default value, which is generally line buffering for tty devices and full buffering for other files. If this parameter is omitted, the system default value is used. ### Return Value Returns an open file object with a file descriptor fd. ### Example The following example demonstrates the use of the popen() method: #!/usr/bin/python3import os, sys # Using the 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 [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Heap IndexHeap Sort β†’