popen python_Python子进程和Popen()及其示例

popen python

popen python

Python provides a lot of functionalities with different modules and libraries. When we need to open a new process inside a Python application we can use subprocess library and related functions.

Python提供了许多具有不同模块和库的功能。 当我们需要在Python应用程序中打开新进程时,可以使用subprocess进程库和相关函数。

导入子流程模块 (Import subprocess Module)

In order to use related functions and libraries, we should import the subprocess library.

为了使用相关的功能和库,我们应该导入subprocess库。

import subprocess

使用call()函数启动子流程 (Start Sub-Process with call() Function)

The simples use case to create a subprocess is using call() function. call() function accepts related binary or executable name and parameters as Python list. In this example, we will call Linux ls command with -l and -a parameters.

创建子流程的简单用例是使用call()函数。 call()函数接受相关的二进制或可执行文件名称和参数作为Python列表。 在此示例中,我们将使用-l-a参数调用Linux ls命令。

subprocess.call(['ls','-l','-a'])
Start with call Function
Start with call Function
从通话功能开始

创建自己的外壳程序(Create Own Shell For Process)

While creating a new process the newly created process will use current python shell and associated variables. We can specify the to create a new shell with the shell=True like below.

在创建新进程时,新创建的进程将使用当前的python shell和关联的变量。 我们可以指定来使用shell=True创建一个新的shell,如下所示。

subprocess.call(['ls','-l','-a'],shell=True)
Create Own Shell For Process
Create Own Shell For Process
创建自己的外壳程序
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值