0
我有以下Python代碼,我通過從python腳本內嵌入bash命令來調用Makefile。我想檢查一下警告是否在stdout上報告。我確實在stdout上看到了警告,但我的Python代碼似乎沒有檢測到它。無法正確解析Python的bash輸出
Python代碼:
maker = subprocess.Popen(["bash", "-c", "make"], stdout=subprocess.PIPE)
for line in maker.stdout:
if "warning:" in line:
print "Warning(s) detected in make"
在標準輸出上輸出,明確報告警告:
main.c: In function ‘main’:
main.c:46:14: warning: unused variable ‘options’ [-Wunused-variable]
編譯器錯誤消息會打印到標準錯誤,而不是標準輸出。 – Barmar