python 重定向shell执行输出

来源:互联网 发布:99云呼软件 编辑:程序博客网 时间:2024/05/29 18:50
本文有两个主题:

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分词程序的,传递纯文本文件的路径,然后将结果返回。