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
0
votes
1 answer

How to spawn a terminal?

I can't find an example of pexpect spawning a Linux terminal. child = pexpect.spawn('/bin/bash') does nothing and the script just insta-closes. This is probably a really stupid question, sorry for that.
user2579116
  • 473
  • 1
  • 4
  • 8
0
votes
1 answer

Pexpect throws unicode decode error when make command is run to compile C libraries

I am running make to compile C libraries in a python project and using python(python 3.3) pexpect for automation part. So the output of make command is read in chunks by pexpect and in one such chunk it throws the following error when the pexpect…
user634615
  • 647
  • 7
  • 17
0
votes
1 answer

python librairie winexpect don't work

i tried to use winexpect librairie winexpect but it's fail on windows ! >>> import pexpect >>> pexpect.spawn(" ") Traceback (most recent call last): File "", line 1, in File…
Thomas
  • 1,008
  • 3
  • 16
  • 34
0
votes
3 answers

Problem with pexpect and 'chained' function calls

The class below is designed to manipulate a cisco-like device interface, for the purpose of executing commands and updating configuration elements. As is currently stands, I can instantiate the class, make a call to the ssh_to_aos_expsh function and…
Rob Carr
  • 270
  • 6
  • 13
0
votes
1 answer

Pexpect Multiple, Different Prompts

Script-1 can be run from a shell and will ask the user for 3 prompts, A, B, and C in that order. A or B will appear to the user, and C will always will appear. In other words, when Script-1 is run, the user will be prompted by question A or B. Once…
mh00h
  • 1,824
  • 3
  • 25
  • 45
0
votes
1 answer

pexpect.spawn('sudo ssh somehost') asks for sudo password every time

I have a series of bash scripts that rely on sudo to ssh/scp some host with root privileges. So I made a python script sshOK that uses pexpect to handle all the nitty gritty of sshing a host, such as answering yes to store keys and return true if…
Klaus Wik
  • 31
  • 3
0
votes
1 answer

very complex quotes in python/shell string

I have a very long string ssh_cmd, I get it from cmd = """kill -9 `ps -ef|grep "udp_receiver"|grep -v "grep"|awk '{print $2}'`""" HostName="133.33.22.1" ssh_cmd = """ssh -t inria_spoofing@{0} 'sudo nohup bash -c "{1} > /nohup.out 2>&1…
misteryes
  • 2,167
  • 4
  • 32
  • 58
0
votes
4 answers

password expect expression isn't getting matched

I started using the Pexpect library and for some reason I am having problems getting expressions to get matched. For example in the following code import pexpect child=pexpect.spawn('su') i=child.expect_exact('Password:') print "value…
metric-space
  • 541
  • 4
  • 14
0
votes
1 answer

Without exiting from the ssh_tunnel, open new terminal

I am using Python and wxpython for gui. I am trying to connect ssh tunnel. After connecting to ssh, wants a new terminal to open and have to continue my operation in local machine. How to achieve this? I tried subprocess, pexpect and paramiko, but…
nammu
  • 71
  • 1
  • 1
  • 10
0
votes
2 answers

Mkdir over SSH with Python does not work

I'm trying to create a new dir via SSH with a python script. When i try my commands by using the Python command line it just works. But when I try to do the same by a script it does not create the new 'test' folder (I even copy/paste the commands in…
Nicholas
  • 1,189
  • 4
  • 20
  • 40
0
votes
1 answer

Use Pexpect or expect for a ssh task, and how to capture errors

I want to use an expect or Pexpect file to automate a shell command like: for host in HostList: ssh -t kitty@host 'sudo nohup bash -c "./tcp_sender > /dev/null 2>&1 &"' if I manually input the command, there are 3 possibilities for case 2, I…
misteryes
  • 2,167
  • 4
  • 32
  • 58
0
votes
0 answers

Executing a shellscript with parameters remotely with pexpect/pxssh

I am trying to use pexpect and pxssh to automate some tasks. I am not very familiar with python. I would like to run a shellscript with some arguments on a server. But the shellscript is hosted locally. I am now trying to do it like this: s =…
Carlito
  • 805
  • 10
  • 20
0
votes
1 answer

Python Pexpect: TypeError: unsupported operand type(s) for %: 'int' and 'dict'

When I try to run the following pexpect command i get the error: TypeError: unsupported operand type(s) for %: 'int' and 'dict'. I do not really understand why I am getting this error. When I do a print of the string I am outputting the results are…
WorkerBee
  • 683
  • 3
  • 11
  • 22
0
votes
1 answer

Getting multi-threading to work with a list using python pexpect

I wrote a simple python pexpect script to ssh into a machine and perform a action. Now I need to do this action to multiple servers. I am using a list to hit all of the servers concurrently using multi-threading. My issue is due to everything being…
WorkerBee
  • 683
  • 3
  • 11
  • 22
0
votes
2 answers

Alternative to scraping netstat for getting list of remote IP addresses?

I'm currently scraping the output of netstat -n -A inet on Linux and netstat -n -f inet on Mac OSX to get a collection of remote IP addresses and ports to which the machine is connected using the following (Python default)…
OregonTrail
  • 8,594
  • 7
  • 43
  • 58