歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Python 重定向shell執行輸出

Python 重定向shell執行輸出

日期:2017/3/1 9:55:38   编辑:SHELL編程

本文有兩個主題:

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分詞程序的,傳遞純文本文件的路徑,然後將結果返回。

Copyright © Linux教程網 All Rights Reserved