Python 重定向shell执行输出

2014-11-24 03:17:14 · 作者: · 浏览: 3

本文有两个主题:


1.python执行shell


os.system("command line")


2.重定向之后shell后的输出


def getkeyword(puretext):
try:
app = ['java','-cp','IKAnalyzer2012_u6.jar:.','htParticiple','-f','acm.nyist.net'] #call the java programe
proc = subprocess.Popen(app,stdout=subprocess.PIPE) #redirect the python out
return proc.stdout.read()
except:
return "ERROR"


这个代码是执行java分词程序的,传递纯文本文件的路径,然后将结果返回。