网络编程
位置:首页>> 网络编程>> Python编程>> 在python 中实现运行多条shell命令

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

作者:xiojing825  发布时间:2023-07-30 10:40:11 

标签:python,shell

使用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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com