import pexpect
child = pexpect.spawn('server stop')
child.expect_exact('Password:')
child.sendline('password')
print('Stopping the servers...')
index = child.expect_exact(['Server processes successfully stopped.',
    'Server is not running...'], 60)
child.expect(pexpect.EOF)
Заставить python вводить пароль при запуске скрипта csh