How to get Fabric to automatically (instead of user-interactively) interact with shell commands? Combine with pexpect?

前端 未结 3 512
不知归路
不知归路 2020-12-05 05:18

Seeking means to get Fabric to automatically (instead of user-interactively) interact with shell commands (and not just requests for passwords, but also requested user input

3条回答
  •  Happy的楠姐
    2020-12-05 05:51

    For Windows users, use winpexpect. Make sure to use this version I linked as this version fixes some bugs in previous versions.

    import sys, winpexpect
    child = winpexpect.winspawn('ftp', [''])
    child.logfile = sys.stdout
    child.expect('User.*:')
    child.sendline('username')
    child.expect('Password:')
    child.direct_sendline('password')
    child .sendline('ls')
    print('Now enter the FTP interactive mode')
    child.interact()
    

提交回复
热议问题