首页 > 编程语言 >当前python程序执行过程中执行其它的python程序(使用内置库subprocess)

当前python程序执行过程中执行其它的python程序(使用内置库subprocess)

时间:2022-12-02 10:45:56浏览次数:41  
标签:None 程序执行 python scratch py subprocess 执行

import subprocess
import time

#
# subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False,
#                cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None,
#                universal_newlines=None)

# 当子进程执行完才会执行后续主进程的代码
# subprocess.run("python scratch.py", shell=True)
# print("scratch.py执行完才会执行我")

# 默认不会等子进程执行完就会执行后续主进程的代码 如果主进程的代码执行完子进程没有执行完也会被终止
# s = subprocess.Popen("python scratch.py", shell=True)
# print("我不会等scratch.py执行完才执行,我先执行")

# s对象引用了wait方法 会等待子进程执行完才会执行后续主进程的代码
# s = subprocess.Popen("python scratch.py", shell=True)
# s.wait()
# print("scratch.py执行完才会执行我")

# cwd属性值用来切换到执行子进程代码的当前目录下
# s = subprocess.Popen("python scratch.py", shell=True, cwd="./h")
# s.wait()
# print("scratch.py执行完才会执行我")

 

参考文章:https://www.runoob.com/w3cnote/python3-subprocess.html

标签:None,程序执行,python,scratch,py,subprocess,执行
From: https://www.cnblogs.com/li-han-qiang/p/16943673.html

相关文章

  • study-python 一个用于保存python学习的代码的仓库
    opencv-study文件夹2022年11月30创建OpenCV是一个图像处理库。它包含大量图像处理函数day01文件夹p1.py本代码功能:读取图像数据img=cv.imread(cv.samples.findFi......
  • python脚本打包
    python脚本打包Python写脚本很方便,可以直接在机器上运行,但有时候脚本源码不方便透露或是其他机器不支持的原因,需要将其打包成可执行文件,需要用到pyinstaller首先下载pip......
  • 互联网下载Python Downloader
    你们可能使用下载软件从Internet下载照片或视频,但现在你可以使用PythonIDM模块创建自己的下载器。#PythonDownloader#pipinstallinternetdownloadmanagerimpo......
  • python生成requirements.txt文件
     使用步骤: 1、先安装pipreqs库pipinstallpipreqs2、在当前目录使用生成pipreqs./--encoding=utf8--force            --encoding=utf8:......
  • Python加密操作 对称加密/非对称加密
    安装包: pycryptodomehttps://pycryptodome.readthedocs.io/en/latest/src/installation.html#compiling-in-linux-ubuntu 1fromCrypto.HashimportSHA2562f......
  • python PIL resize
    https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resizeImage.resize(size,resample=None,box=None,reducing_gap=None)[source]Re......
  • How to get file size in Python? 获取文件大小Python
    HowtogetfilesizeinPython?WecanfollowdifferentapproachestogetthefilesizeinPython.It’simportanttogetthefilesizeinPythontomonitorfi......
  • Python13-实战
    实战01(模拟篮球自动弹跳)#-*-coding:utf-8-*-importsys#导入sys模块importpygame#导入pygame模块pygame.init()#初始化pygamesize=width,height=640,......
  • python第13章实例
    #_*_coding:utf-8_*_importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.ima......
  • Python第十三章小球移动游戏
    #-*-coding:utf-8-*-importsys#导入sys模块importpygame#导入pygame模块pygame.init()#初始化pygamesize=width,height=640,480#设置窗口screen=pyga......