2013-07-24 30 views
6

我試圖grep的日誌中包含multipe行消息時遇到以下錯誤...任何人都可以提供有關如何克服此錯誤的輸入?bufsize必須是一個整數錯誤,同時grepping一條消息

CODE: -

print gerrit_commitmsg 
    gerritlog = Popen('git','log','--grep','gerrit_commitmsg', stdout=PIPE, stderr=PIPE) 
    print gerritlog 

錯誤: -

Commit message:- 

Build system changes 

Build system changes to include packages in the build 

Change-Id: I697558f01ae367d2baacdf2c7fcf1a03753edacd 

Traceback (most recent call last): 
    File "gerrits_in_workspace.py", line 87, in <module> 
    main() 
    File "gerrits_in_workspace.py", line 77, in main 
    grep_commitmsg(gerrit_commitmsg) 
    File "gerrits_in_workspace.py", line 48, in grep_commitmsg 
    gerritlog = Popen('git','log','--grep','gerrit_commitmsg', stdout=PIPE, stderr=PIPE) 
    File "/usr/lib/python2.7/subprocess.py", line 629, in __init__ 
    raise TypeError("bufsize must be an integer") 

回答

14

subprocess.Popen類預期的參數列表如下:

Popen(args, bufsize=0, ...) 

所以你傳遞:

  • args = git
  • bufsize = log

因此,誤差(bufsize期望的整數值)。命令矢量需要一個列表,像這樣:

gerritlog = Popen(['git','log','--grep','gerrit_commitmsg'], stdout=PIPE, stderr=PIPE) 
+0

感謝,我也想給grep什麼是gerrit_commitmsg但不是字符串gerrit_commitmsg本身,對任何提示我們該怎麼辦呢? – user1934146

+0

這是一個不同的問題,你最好打賭可能在這裏發佈一個新的問題。 – larsks

相關問題