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
0 answers

Pexpect child not reading config file

I'm trying to use pexpect to open pianobar (a client for Pandora online radio). If I just start pianobar from the command line (not from my Python program), it logs in automatically using info from the config file (Email, Password,…
0
votes
3 answers

pexpect output not showing

Our simple pexpect script has this: import pexpect import sys test = pexpect.spawn('ftp www.today.com') test.logfile = sys.stdout test.expect('Name.*') However, on the shell the script was invoked, there's no output shown. Instead it seems to hang…
chz
  • 355
  • 1
  • 7
  • 21
0
votes
1 answer

Is pexpect the right tool for subprocess?

We have an app.exe that uses another 3rd party installation wizard app, InstallAnywhere, to install our application. It is a text-based wizard - meaning a new shell is spawned (and the child process is executing some java.exe in order for its wizard…
chz
  • 355
  • 1
  • 7
  • 21
0
votes
2 answers

Communicate with Rar.exe in Python

From a Python script I want to create a RAR file. I will need to communicate with Rar.exe because I only want the first RAR volume from a multi-volume archive set, nothing more. The -vp switch makes sure Create next volume ? [Y]es, [N]o, [A]ll is…
Gfy
  • 8,173
  • 3
  • 26
  • 46
0
votes
2 answers

How to login the super user(root) in remote host system using pexpect?

How to login the super user(root) in remote host system using pexpect? user = root user password = 'pass' child = pexpect.spawn('ssh %s@%s'%(user,host,))
Reegan Miranda
  • 2,879
  • 6
  • 43
  • 55
0
votes
0 answers

pexpect telnet into one device and then from there to another

I am trying to use pexpect to telnet to a device and then subsequently telnet from that device to another device and then output the result of a command on the second device but i am unable to. Here is the script i wrote and the error i am getting I…
user2041020
  • 11
  • 1
  • 2
0
votes
2 answers

Errors when connecting to router with python code

I am trying to connect to some router using the above code and I am using juniperj2320.py module and in test file I have am using code base from this http://subversion.assembla.com/svn/clauzsistel08/trunk/dist/ #!/usr/bin/python from localconf…
bana
  • 397
  • 1
  • 5
  • 16
0
votes
2 answers

Automate `svn up` with password entry

I need a script that updates my copy of a repository. When I type "svn up" I usually am forced to enter a password, how do I automate the password entry? What I've tried: import pexpect, sys, re pexpect.run("svn cleanup") child =…
dranxo
  • 3,348
  • 4
  • 35
  • 48
0
votes
1 answer

Why isn't pexpect consuming the output from the shell properly?

I am running Solaris 5-10, python 2.6.2 and pexpect 2.4 I have the very simple python script below which exercises the functionality of sending and receiving text from the shell. My understanding is that pexepect([pexpect.TIMEOUT, x,y,z],…
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
0
votes
1 answer

how to match a regular expression like (%i1) in python pexpect

I want to use maxima from python using pexpect, whenever maxima starts it will print a bunch of stuff of this form: $ maxima Maxima 5.27.0 http://maxima.sourceforge.net using Lisp SBCL 1.0.57-1.fc17 Distributed under the GNU Public License. See the…
mike
  • 897
  • 2
  • 10
  • 29
0
votes
1 answer

Python pexpect sendline contents being buffered?

I have the following code in Python using the pexpect module to run a perl script which asks a series of questions. I have used this for quite some time and works well until now. pexpect python index = child.expect(['Question 1:']) os.system('sleep…
gqdabien
  • 25
  • 1
  • 4
0
votes
1 answer

pexpect responses includes echos of requests with

I have used pexpect and sendline before, but this time I am running a longer command with pipes and wild card, see below: commandToRun='/bin/bash -c "/var/scripts/testscripts//extract -o | tail -3"' returnedString = sendLine(commandToRun) my class…
theAlse
  • 5,577
  • 11
  • 68
  • 110
0
votes
1 answer

pexpect.run can not run a long command

I am using pexpect.run to execute a command. See below: cmd = "grep -L killed /dir/dumps/*MAC-66.log" output = pexpect.run(cmd) When I run this, output equals to: grep: /dir/dumps/*MAC-66.log: No such file or directory But when I run the same…
theAlse
  • 5,577
  • 11
  • 68
  • 110
0
votes
2 answers

Pexpect does not respect timeouts

pexpect is not working with time outs. import pexpect import sys import os os.system("""git config --global user.name '#{git_name}'""") os.system("""git config --global user.email '#{git_email}'""") child = pexpect.spawn ('git clone…
Tampa
  • 75,446
  • 119
  • 278
  • 425
0
votes
1 answer

pexpect need to use pipe without starting the bash shell since the bash shell does not understand the command

I want to do something likethis using pexpect echild = pexpect.spawn('/bin/bash -c "sysinfo -v | grep "SCM"') fout = file('/home/kiva/release_file.txt' , 'w+') child.logfile = fout The problem is that I want the out of that command into a textfile…
andybandy12
  • 69
  • 2
  • 8