Python 3 : Using subprocess Instead Of os. 系统

标签 python python-3.x subprocess sys os.system

我有一个名为 variable 的字符串,需要执行与 os.system 等效的 subprocess 操作。我试图找到一种方法来做到这一点,但只发现:

variable2 = subprocess.Popen(args, stdout=subprocess.PIPE)
print variable2.communicate()[0]

但是,我无法理解如何使用它。我如何实现我的目标?

最佳答案

该文档提供了几个旧式子流程创建函数的等效项。 os.system() 解释here .

关于Python 3 : Using subprocess Instead Of os. 系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9443606/

相关文章:

python - 管理 Python 脚本的 shell 命令结果

python - CalledProcessError 在 apache 上导致 500 错误,即使它被(或应该)捕获

python - 如何使用ctypes(C++到Python)将opencv3 cv::Mat转换为numpy数组?

python - 当我尝试使用 BeautifulSoup 解析 HTML 页面时出现 "TypeError: string indices must be integers"错误

python - GAE 和 Facebook 连接 : How to get age and gender of user?

python-3.x - 下拉菜单更改顺序并每次删除一个选项 - Python

python - 如何为不同的实现提取学习到的 ML 模型?

python-3.x - PythonPDF : FileNotFoundError: [WinError 2] The system cannot find the file specified

python - 如何利用 GPU 将大型 dask 数组 (numpy.ndarray) 写入 Zarr 文件?

python - 如何告诉 BeautifulSoup 将特定标签的内容提取为文本? (不碰它)