1

I'm using pexpect to a remote server and handover screen to me. the script run success. only problem is that the screen output kind of get squeezed after login using pexpect. it's like not getting a full screen terminal for input and output. the impact is while input command it could cause problem and some content can't be fully displayed.(get a "newline" in the middle of the screen) but i'm sure there's no problem with the screen output by using normal ssh login.

I use Iterm2 for remote login, but whatever Iterm or terminal. issue is the same.

import pexpect
import getpass, os , sys
from time import sleep

def ssh_command (user,password,servername):
    ssh_newkey = 'Are you sure you want to continue connecting'
    child = pexpect.spawn('ssh -l %s %s  '%(user, servername))
    fout = open('mylog.txt','wb')
    child.logfile = fout
    i = child.expect([pexpect.TIMEOUT, ssh_newkey, 'password: '],timeout =5)
    if i == 0: # Timeout
        print('ERROR!')
        return None
    if i == 1: # SSH does not have the public key. Just accept it.
        child.sendline ('yes')
        child.expect ('password: ')
        i = child.expect([pexpect.TIMEOUT, 'password: '],timeout =5)
        if i == 0: # Timeout
            print('ERROR!')
        return None
    child.sendline(password)
    child.interact()

expect output(like normal ssh login):

Mac:user|/var $ ssh admin101
user@admin101's password:
[user@admin101 ~]$ echo "1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890"

squeezed terminal output(by using pexpect):

Mac:user|/var $ python remote.py
4567890an@admin101 ~]$ echo "1234567890 1234567890 1234567890 1234567890 123
Kenster
  • 23,465
  • 21
  • 80
  • 106
The_flash
  • 184
  • 1
  • 1
  • 11
  • https://stackoverflow.com/a/39358807/13317 ? – Kenster Jun 26 '19 at 15:05
  • @kenster that's awesome ! set the winsize actually solve my problem. you saved my world ! appreciate so much ! – The_flash Jun 27 '19 at 06:26
  • Possible duplicate of [How do I set the column width of a pexpect ssh session?](https://stackoverflow.com/questions/39357149/how-do-i-set-the-column-width-of-a-pexpect-ssh-session) – Kenster Jun 27 '19 at 10:05

0 Answers0