首页 > 文章列表 > python中subprocess的用法

python中subprocess的用法

Python subprocess
105 2022-08-07

1、subprocess这个模块来产生子进程,并且可以连接到子进程的标准输入、输出、错误中,还可以获得子进程的返回值。

2、subprocess提供了2种方法调用子程序。

实例

# coding:utf-8
 
import os
 
# popen返回文件对象,同open操作一样
f = os.popen(r"ls", "r")
 
l = f.read()
print(l)
f.close()

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。