2013-01-08 113 views
1

根據幫助汞柱驗證不返回0或1

$ hg -v help verify 
hg verify 

verify the integrity of the repository 

    Verify the integrity of the current repository. 

    This will perform an extensive check of the repository's integrity, 
    validating the hashes and checksums of each entry in the changelog, 
    manifest, and tracked files, as well as the integrity of their crosslinks 
    and indices. 

    Returns 0 on success, 1 if errors are encountered. 

從控制檯

>>> from subprocess import Popen, PIPE 
>>> p = Popen(['hg', 'verify', '-R', 'sample-master'], stdout=PIPE, stdin=PIPE) 
>>> out, err = p.communicate() 
>>> out 
'checking changesets\nchecking manifests\ncrosschecking files in changesets and manifests\nchecking files\n2186 files, 214 changesets, 3055 total revisions\n' 
>>> err 
>>> """-q is quite suppress output""" 
>>> p = Popen(['hg', 'verify', '-R', 'sample-master', '-q'], stdout=PIPE, stdin=PIPE) 
>>> out, err = p.communicate() 
>>> out 
'' 

輸出我現在損壞的.hg/store

>>> out, err = Popen(['hg', 'verify', '-R', 'sample-master', '-q'], stdout=PIPE, stdin=PIPE, stderr=PIPE).communicate() 
>>> out, err 
('', ' data/[email protected]: missing revlog!\n 119: empty or missing req.txt\n [email protected]: 8befed264a2f in manifests not found\n3 integrity errors encountered!\n(first damaged changeset appears to be 119)\n') 

我沒有看到0或1.我錯過了什麼?

謝謝。

回答

3

您正在尋找process return code

p = Popen(['hg', 'verify', '-R', 'natrium-master', '-q'], stdout=PIPE, stdin=PIPE) 
out, err = p.communicate() 
print p.returncode 

的文件指的是過程的exist status

+0

啊。我從來不知道這一點。所以習慣閱讀stdin和stdout。困惑。現在我學到了些東西。非常感謝。 – CppLearner

+0

@CppLearner - 如果你想要在'sh'風格的shell中從最後執行的程序返回代碼,你可以從'$?'得到它 – mgilson

+0

@mgilson只需要提供'$?'給Popen? – CppLearner