python-python中插入shell命令

python-python中插入shell命令,第1张


title: python-python中插入shell命令
date: 2022-05-15 13:10:34
tags: python subprocess 示例代码
import subprocess
cmd = 'cat a.py; cat b.py'
subprocess.call(cmd, shell=True)
# subprocess.call(cmd, shell=False)

# out
print('hello.py')print('b.py'
subprocess shell=False 与shell=True的区别

shell = True
会让subprocess.call接受字符串类型的变量作为命令,并调用shell去执行这个字符串
shell = False
subprocess.call只接受数组变量作为命令,并将数组的第一个参数元素作为命令,剩下的全部作为该命令参数。

subprocess 示例代码
import os
cmd = 'cat a.py; cat b.py'
os.system(cmd)

# out
print('hello.py')print('b.py')

只接受一个参数

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/921589.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存