Questions tagged [pexpect]

Pexpect is a pure Python module that reads the output of a program and sends input to that program based on output patterns. It can be used to automate interactions with interactive programs. It is inspired by the classic TCL expect program.

Pexpect is a pure Python module for controlling and automating other programs. It

Pexpect is similar to the Don Libes Expect system in TCL, but with a different interface that is intended to be easier to understand.

Pexpect is basically a pattern matching system. It runs programs and watches output. When the output matches a given pattern Pexpect can respond by sending input to the program. Pexpect can be used for automation, testing, and screen scraping of interactive programs. From the project description:

Pexpect can be used for automating interactive console applications such as ssh, ftp, passwd, telnet, etc. It can also be used to control web applications via lynx, w3m, or some other text-based web browser. Pexpect is pure Python. Unlike other Expect-like modules for Python Pexpect does not require TCL or Expect nor does it require C extensions to be compiled. It should work on any platform that supports the standard Python pty module.

Resources

820 questions
-2
votes
1 answer

Using pexpect to send a second password, but not working?

I'm trying to use pexpect to send a password. It works the first time when prompted for a password (at "azureuser@xx.xx.xx.xxx's password:") but not the second time (at "[sudo] password for azureuser:"). Why is this so? I need to stay within the…
greendaysbomb
  • 364
  • 2
  • 6
  • 23
-2
votes
1 answer

How to pass "yes/no" to prompt from python code?

I have tiny little python code which logs in to a remote machine and gets the output of a command and prints to a file.. Here for a particular command, the server asks for Y or N, how do i pass an Yes to it and get the desired output? Here is the…
redpy
  • 143
  • 5
-2
votes
1 answer

Switch between interactive and non-interactive mode in pexpect

I am using pexpect to upload a file to SFTP server. For accesssing the server first time, I get message as The authenticity of host..can't be established.Are you sure you want to continue connecting (yes/no)? to which I want the user to interact…
Simplecode
  • 559
  • 7
  • 19
-2
votes
1 answer

python output of pexpect

def connect(user,host,keyfile,release): global Stop global Fails try: perm_denied = 'Permission denied' ssh_newkey = 'Are you sure you want to continue' conn_closed = 'Connection closed by remote…
Robbie
  • 53
  • 1
  • 8
-2
votes
2 answers

Running pexpect subprocesses in background

I have the below code that I am running try: child = pexpect.spawn( ('some command --path {0} somethingmore --args {1}').format( ,something), timeout=300) child.logfile = open(file_name,'w') …
-2
votes
2 answers

Python,using pexpect to connect to a switch

I am trying to connect a switch Juniper using pexpect library to get some interfaces informations, here is my code: import pexpect child = pexpect.spawn('ssh root@10.171.23.246') child.expect('login as:…
manoman
  • 1
  • 1
  • 3
-2
votes
1 answer

Preserve the formatting(whitespace & newlines) of the response received from executing a command over ssh

I am writing an application in Python, I am using pexpect ( more specifically the pxssh functionality) to execute a series of commands on a Cisco Router. I want to store the output returned to a variable intact with the whitespaces and the newlines.…
-2
votes
1 answer

How do i write the output to a file and to the stdout using pexpect module

I'm a newbie to python and have been reading and surfing the net to accomplish my task. I'm writing a function which will do a ssh to my device, execute few commands and display the result both in terminal and into a log file. i have written…
user596922
  • 1,501
  • 3
  • 18
  • 27
-2
votes
1 answer

pexpect prompt for blank space in python

Can any one please tell me, what is the prompt we have to give for expecting a blank space for a python script.I need to execute a command which will execute only after it sees the expect prompt.On doing manually i got that the prompt is a blank…
abhi
  • 368
  • 1
  • 4
  • 14
-3
votes
1 answer

How to keep bash array valid with python send cmd

I have an array in bash script. This script gets executed through python send command and while executing the array line of the script, it returns - Syntax error: "(" unexpected due to this line of code - pci_addr_0=`lspci | grep -i abcde | grep -i…
RV5
  • 1
  • 1
1 2 3
54
55