在python 中实现运行多条shell命令
作者:xiojing825 时间:2023-07-30 10:40:11
使用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文件
来源:https://blog.csdn.net/xiojing825/article/details/78207862
标签:python,shell
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL语句实现查询当前数据库IO等待状况
2024-01-17 02:04:32
Flask框架工厂函数用法实例分析
2023-03-08 08:14:30
安装Mysql5.7.10 winx64出现的几个问题汇总
2024-01-28 13:16:04
Python ljust rjust center输出
2021-05-13 04:19:25
Python如何筛选序列中的元素的方法实现
2021-06-12 03:31:51
Golang控制协程执行顺序方法详解
2024-02-20 13:00:21
Django使用消息提示简单的弹出个对话框实例
2023-02-08 06:23:07
![](https://img.aspxhome.com/file/2023/1/66911_0s.jpg)
tensorflow 环境变量设置方式
2021-10-09 16:53:51
![](https://img.aspxhome.com/file/2023/5/99115_0s.jpg)
pytorch plt.savefig()的用法及保存路径
2021-04-28 12:55:44
![](https://img.aspxhome.com/file/2023/9/105779_0s.png)
Python开发桌面小程序功能
2023-07-01 14:46:59
![](https://img.aspxhome.com/file/2023/3/110463_0s.png)
Windows10使用Anaconda安装Tensorflow-gpu的教程详解
2023-09-21 14:50:15
![](https://img.aspxhome.com/file/2023/0/107170_0s.png)
JavaScript实现自动变换表格边框颜色
2024-06-07 15:25:53
python自动化测试用例全对偶组合与全覆盖组合比较
2021-02-03 01:59:45
![](https://img.aspxhome.com/file/2023/1/78481_0s.png)
仿阿里巴巴搜索导航设计效果
2008-04-15 15:01:00
![](/images/sg_trans.gif)
Systemd 入门实战教程
2022-10-29 15:52:44
Python 实现中值滤波、均值滤波的方法
2022-05-09 08:58:38
![](https://img.aspxhome.com/file/2023/0/121100_0s.jpg)
MySQL数据表分区策略及优缺点分析
2024-01-22 05:37:19
Python交互式图形编程的实现
2021-09-04 18:19:15
![](https://img.aspxhome.com/file/2023/9/65929_0s.png)
go MethodByName()不能获取私有方法的解决
2024-04-30 10:07:35
![](https://img.aspxhome.com/file/2023/7/130687_0s.png)
Python CSS选择器爬取京东网商品信息过程解析
2022-01-17 21:18:17
![](https://img.aspxhome.com/file/2023/0/124360_0s.jpg)