当前位置: 移动技术网 > IT编程>脚本编程>Python > 在python 中实现运行多条shell命令

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

2019年03月21日  | 移动技术网IT编程  | 我要评论

钢度网,品众进货助手,iristop

使用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命令就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网