2012-08-06 36 views
3

考慮以下sudo呼叫使用面料不正確的輸出:面料須藤()拍攝時,用戶最初進入錯誤的密碼

def ls(): 
    output = sudo('ls /tmp/', user = 'someone', shell = True) 
    print "Output:", output 

執行此使用fab並輸入錯誤密碼,您被sudo提示第一次。您會看到一條錯誤消息,sudo會再次要求您輸入密碼。第二次輸入正確的密碼。會議看起來是這樣的:

$ fab ls 
[[email protected]] Executing task 'ls' 
[[email protected]] sudo: ls /tmp/ 
[[email protected]] out: sudo password: 

[[email protected]] out: Sorry, try again. 
[[email protected]] out: sudo password: 

[[email protected]] out: hsperfdata_someone 

Output: Sorry, try again. 

Done. 

output價值是如何被輸入了錯誤的密碼時,由sudo打印的第一條消息(「對不起,再試一次。」)。它不包含隨後的正確輸出(「hsperfdata_someone」)。

我做錯了什麼?在這種情況下是否有更好的方法來正確捕獲輸出?

回答

2

我想說這可能是一個要報告的錯誤,但你可以看看this section的一些不同的組合來嘗試。

+1

沒有運氣雜耍'pty'和'combine_stderr'。我已經提出這個錯誤。 – 2012-08-06 17:14:59

+0

認爲這是事實,但無論如何值得一試。感謝您報告這一點。 – Morgan 2012-08-06 19:45:34