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 plaincopyhandle = subprocess.Popen('ls -l', stdout=subprocess.PIPE, shell=True)
print handle.stdout.read()
print handle.communicate()[0]
python 去掉特殊字符
lstrip和rstrip 分别去首尾字符
例如:
[html]
view plaincopytheString = 'saaaay yes no yaaaass'
print theString.strip('say')
print theString.strip('say ') #say后面有空格
print theString.lstrip('say')
print theString.rstrip('say')
结果:
[html]
view plaincopyyes no
es no
yes no yaaaass
saaaay yes no
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。