打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
python 中运行linux shell脚本
python 中运行linux shell脚本
分类: python2012-11-29 13:48 585人阅读 评论(0) 收藏 举报
subprocess.Popen(command, shell=True)
如果command不是一个可执行文件,shell=True不可省。
最简单的方法是使用class subprocess.Popen(command,shell=True)。
Popen类有Popen.stdin,Popen.stdout,Popen.stderr三个有用的属性,可以实现与子进程的通信。
例如:
[html] view plaincopy
handle = subprocess.Popen('ls -l', stdout=subprocess.PIPE, shell=True)
print handle.stdout.read()
print handle.communicate()[0]
python 去掉特殊字符
lstrip和rstrip 分别去首尾字符
例如:
[html] view plaincopy
theString = 'saaaay yes no yaaaass'
print theString.strip('say')
print theString.strip('say ') #say后面有空格
print theString.lstrip('say')
print theString.rstrip('say')
结果:
[html] view plaincopy
yes no
es no
yes no yaaaass
saaaay yes no
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
python调用shell命令的方法
python执行shell的两种方法
popen的使用
Linux下使用popen()执行shell命令
sublime3插件开发
python学习 subprocess模块
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服