python pexpect模块详解_python-pexpect模块几乎不需要帮助

需要有关pexpect模块的帮助

我写了一个简单的代码,它将使用ssh从服务器克隆git存储库.

我正面临几个问题.

密码以纯文本显示.

下载后我不知道退出程序的正确方法.它抛出以下错误…

Traceback (most recent call last):

File "ToDelete3.py", line 65, in

# # 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://username@someserver/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 '******************************************************

'

p.close()

任何输入都受到高度赞赏.

谢谢.

-Vijay

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值