Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8157731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:23:04+00:00 2026-06-06T17:23:04+00:00

Need assistance with the pexpect module I have written a simple code which would

  • 0

Need assistance with the pexpect module

I have written a simple code which would clone a git repository from a server using ssh.
I’m facing couple of problems.

The password is shown in plain text.

I dont know a proper way to exit the program after the download. it throws out the following error…

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

the code that I have written so far is :

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 '******************************************************\n\n'
            p.close()

Any inputs is highly appreciated..

Thanks.
-Vijay

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:23:06+00:00Added an answer on June 6, 2026 at 5:23 pm

    There are few errors in the program:

    p.interact()
    

    This is used when we want to get back the control after having automatically supplied the password using pexpect module. You don’t need to use that since you are automating the whole repository check out.

    Also a few things can be improved, after passing the password, set a infinite timeout since it may take a while to copy a git repository.

    p.expect(pexpect.EOF, timeout=None)
    

    After that you can read all the execution output with the following command

    output_lines =  p.before
    output_lines_list = output_lines.split('\r\n')
    for line in output_lines: print line
    

    you can also use the above to log the output to a file by directly writing to it

    Using p.logifile = sys.stdout is not good since it will record pexpect operation from start including passing of password.

    After this there is no need to close, you are not running a interactive program. Remove all these lines:

    if i == 2:
            print 'Inside EOF block'
            if p.isalive():
                print '******************************************************'
                print '         Closing the process of Download !!!          '
                print '******************************************************\n\n'
                p.close()
    

    The issue is that some where you have to store the password and use it with p.sendline. How ever, you store password, it is going to be insecure. You can also take the input at the start for the password, this way you will not be storing the password within your program but that defeats automation. I don’t see a way out but for taking password input, you can do:

    import getpass
    getpass.getpass("please provide your password")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some assistance from the Flex experts. I have an mx:Menubar , which
I am new to jQuery and I need some assistance with very simple code.
Need assistance with the following code, i have a form providing a id, when
I have the following MVC TypeFormatter code and I need assistance how to: Pass
I need some assistance trying to execute a demo print from jzebra to an
I need some assistance with some javascript/jquery I have put in place. The function
I have looked all over the net and need some assistance. Is there a
I am developing a app in android .... which need a code snippet to
I am working on a lab and need some assistance if possible. I have
I've been given a problem that I need some assistance from the SO community

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.