概述

linux中一个进程可以fork一个子进程,并让这个子进程exec另外一个程序。在python中,可以通过标准库中的subprocess包来fork一个子进程,并且运行一个外部的程序。subprocess包中定义有数个创建子进程的函数,这些函数分别以不同的方式创建子进程,所以我们可以根据需要来从中选取一个使用。另外subprocess还提供了一些管理标准流(standard stream)和管道(pipe)的工具,从而在进程间使用文本通信。

subprocess的子模块

  • subprocess.run()
  • subprocess.call()
  • subprocess.check_call()
  • subprocess.getstatusoutput()
  • subprocess.getoutput()
  • subprocess.check_output()

python运行shell命令subprocess的实现

subprocess.Popen()

python运行shell命令subprocess的实现

管道subprocess.PIPE

python运行shell命令subprocess的实现

wait与communicate

python运行shell命令subprocess的实现

stdin, stdout,stderr

python运行shell命令subprocess的实现

原文地址:https://blog.csdn.net/wugou2014/article/details/129150604

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-17
  • 2021-12-06
  • 2021-12-21
  • 2023-01-12
  • 2022-02-02
  • 2022-12-23
相关资源
相似解决方案