一. 简介
前面文章简单学习了 Python3 中 OS模块中的文件/目录的部分函数。
本文继续来学习 OS 模块中文件、目录的操作方法:os.pipe() 方法、os.popen() 方法。
二. Python3 OS模块中的文件/目录方法
1. os.pipe() 方法
os.pipe() 方法用于创建一个管道, 返回一对文件描述符(r, w) 分别为读和写。
pipe()方法语法格式如下:
os.pipe()
返回两个文件描述符:
读端文件描述符(r_fd),用于读取数据。
写端文件描述符(w_fd),用于写入数据。
示例如下:
#!/usr/bin/env python3
import os,sys
print ("The child will write text to a pipe and ")
print ("the parent will read the text written by child...")
r_fd,w_fd = os.pipe()
pid =