需要幫助與pexpect模塊需要與pexpect模塊的一點幫助
我已經寫了一個簡單的代碼,將從服務器使用ssh克隆git存儲庫。 我正面臨着一些問題。
密碼以純文本顯示。
我不知道下載後退出程序的正確方法。它拋出了以下錯誤...
Traceback (most recent call last):
File "ToDelete3.py", line 65, in <module>
# # if i == 1:
File "ToDelete3.py", line 36, in getRepository
i = p.expect([ssh_key,'password:',pexpect.EOF])
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1492, in interact
self.__interact_copy(escape_character, input_filter, output_filter)
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1520, in __interact_copy
data = self.__interact_read(self.child_fd)
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1510, in __interact_read
return os.read(fd, 1000)
OSError: [Errno 5] Input/output error
我寫到目前爲止代碼:
command = 'git clone ssh://[email protected]/something.git'
ssh_key = 'Are you sure you want to continue connecting'
def gracefulExit():
print 'Password Incorrect !!!'
os._exit(1)
def getRepository():
p = pexpect.spawn(command,maxread=10000,timeout = 100)
p.logfile = sys.stdout # logs out the command
i = p.expect([ssh_key,'password:',pexpect.EOF])
if i == 0:
print 'Inside sshkey'
p.sendline('yes')
i = p.expect([ssh_key,'password:',pexpect.EOF])
if i == 1:
try:
p.sendline('mypassword') # this mypassword is shown in clear text on the console
p.interact()
p.logfile = sys.stdout
p.expect(pexpect.EOF)
except Exception,e:
print str(e)
gracefulExit()
if i == 2:
print 'Inside EOF block'
if p.isalive():
print '******************************************************'
print ' Closing the process of Download !!! '
print '******************************************************\n\n'
p.close()
任何輸入的高度讚賞..
感謝。 -Vijay
感謝Pyfunc像寶石一樣工作。感謝您的詳細解釋。有助於更好地理解它..對不起,對於遲到的答覆..是的,確實工作..但一個問題,但。它在我輸入時不顯示密碼,但在此之後看起來像p.logfile = sys.stdout莫名其妙地在終端中以純文本輸出密碼。任何方式來避免這種情況.. – user596922
這有幫助。謝謝 !! – user596922