python 运行多条shell命令 在python 中实现运行多条shell命令

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

python 运行多条shell命令 在python 中实现运行多条shell命令

xiojing825   2021-03-30 我要评论

使用py时可能需要连续运行多条shell 命令

1.

# coding: UTF-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')

import subprocess
import os
import commands

#os.system('cmd1 && cmd2')
cmd1 = "cd ../"
cmd2 = "ls"
cmd = cmd1 + " && " + cmd2

#如下两种都可以运行
subprocess.Popen(cmd, shell=True)
subprocess.call(cmd,shell=True)

2.也可以将多条shell写入.sh 文件.然后运行.sh文件

以上这篇在python 中实现运行多条shell命令就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们