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