Python os.popen () method
Python OS file / directory methods
Outline
os.popen () method is used to open a pipe from a command.
Valid in Unix, Windows in
grammar
popen () method syntax is as follows:
os.popen(command[, mode[, bufsize]])
parameter
command - command.
mode - mode privileges can be 'r' (default) or 'w'.
bufsize - indicates the buffer size required files: 0 means unbuffered; 1 means line buffered; other positive value indicates a buffer size parameter (presumably value, in bytes).The default value is negative bufsize means to use the system, in general, for the tty device, which is the line buffer; the other files, it is fully buffered. If you do not change the parameters, the default values using the system.
return value
It returns a file descriptor number of open file object fd
Examples
The following example demonstrates popen () methods of use:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 使用 mkdir 命令 a = 'mkdir nwdir' b = os.popen(a,'r',1) print b
The above program output is:
open file 'mkdir nwdir', mode 'r' at 0x81614d0