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

yipeiwu_com6年前Python基础

使用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命令就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python基于phantomjs实现导入图片

基于的phantomjs的自动化,会出现 1.flash不支持 2.部分基于view的按钮点不到,部分按钮是基于flash的(尤其是在于上传按钮) browser.find_ele...

python和pygame实现简单俄罗斯方块游戏

python和pygame实现简单俄罗斯方块游戏

本文为大家分享了python实现俄罗斯方块游戏的具体代码,供大家参考,具体内容如下 Github:Tetris 代码: # -*- coding:utf-8 -*- import...

python私有属性和方法实例分析

本文实例分析了python的私有属性和方法。分享给大家供大家参考。具体实现方法如下: python默认的成员函数和成员变量都是公开的,并且没有类似别的语言的public,private等...

Python学习笔记之字符串和字符串方法实例详解

Python学习笔记之字符串和字符串方法实例详解

本文实例讲述了Python学习笔记之字符串和字符串方法。分享给大家供大家参考,具体如下: 字符串 在 python 中,字符串的变量类型显示为 str。你可以使用双引号 " 或单引号 '...

使用Python编写Prometheus监控的方法

要使用python编写Prometheus监控,需要你先开启Prometheus集群。可以参考/post/148895.htm 安装。在python中实现服务器端。在Prometheus...