pexpect

Python how to read output from pexpect child?

你说的曾经没有我的故事 提交于 2019-11-28 23:08:19
child = pexpect.spawn ('/bin/bash') child.sendline('ls') print(child.readline()) print child.before, child.after All I get with this code in my output is ls ls But when my code is child = pexpect.spawn('ls') print(child.readline()) print child.before, child.after Then it works, but only for the first 2 prints. Am I using the wrong send command? I tried send, write, sendline, and couldn't find anymore. Catalin Luta In pexpect the before and after attributes are populated after an expect method. The most common thing used in this situation is waiting for the prompt (so you'll know that the

How to set explicitly the terminal size when using pexpect

∥☆過路亽.° 提交于 2019-11-28 13:35:31
I have a ncurses app that checks terminal size at startup and exits immediately if it doesn't fit. In Linux, the default size is 80x24, this app requires at least 25. The fix is easy, I'm just resizing the terminal emulation window (in X) before running the ncurses app. I would like to automate the ncurses app with pexpect, but I'm getting stuck because it considers the terminal size smaller than required when launched through pexpect, so it doesn't run. Any way to specify the terminal size with pexpect explicitly at startup? Try setting the LINES and COLUMNS environment variables before you

EOF when using pexpect and pxssh

风格不统一 提交于 2019-11-28 07:53:38
问题 I'm trying to run the code in the Interacting with SSH Through Pexpect and Brute Forcing SSH Passwords with Pxssh sections from Chapter 2 of Violent Python. Using both child.expect() and pxssh I get similar EOF errors. Running these commands from the Python console: import pexpect connStr = "ssh root@127.0.0.1" child = pexpect.spawn(connStr) ret = child.expect([pexpect.TIMEOUT, ssh_newkey, "[P|p]assword:"]) I get this output: Traceback (most recent call last): File "<input>", line 1, in

python pexpect: SSHing then updating the date

自作多情 提交于 2019-11-28 07:45:09
问题 I have finally have my python pexpect script working except for the most important part updating the date! I am able to SSH in the box but my second command does not execute properly. I have been banging my head on the wall trying to figure out why. I have checked the output of the sting and it should be working based on whats coded. I am not a expert when it comes to python or pexpect so I am in need of a bit of help figuring out why my time is not updating. my original code : list = ["089"]

python pexpect sendcontrol key characters

不打扰是莪最后的温柔 提交于 2019-11-28 00:58:32
问题 I am working with pythons pexpect module to automate tasks, I need help in figuring out key characters to use with sendcontrol. how could one send the controlkey ENTER ? and for future reference how can we find the key characters? here is the code i am working on. #!/usr/bin/env python import pexpect id = pexpect.spawn ('ftp 192.168.3.140') id.expect_exact('Name') id.sendline ('anonymous') id.expect_exact ('Password') *# Not sure how to send the enter control key id.sendcontrol ('???')* id

How to get Fabric to automatically (instead of user-interactively) interact with shell commands? Combine with pexpect?

筅森魡賤 提交于 2019-11-27 19:26:28
Seeking means to get Fabric to automatically (instead of user-interactively) interact with shell commands (and not just requests for passwords, but also requested user input when no "stdin/interactive override" like apt-get install -y is available). This question along with these Fabric docs suggest that Fabric can only "push the interactivity" back to the human user that's running the Fabric program. Seeking to instead fully automate without any human presence. Don't yet have a "real," current problem to solve, just preparing for possible, future obstacle. Possibly useful to combine with

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available

好久不见. 提交于 2019-11-27 00:37:23
I am using Python3.6, when i try to install "modules" using pip3, i am facing the below mentioned issue "pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available" Please help me to solve this issue For Windows 10 if you want use pip in normal cmd, not only in Anaconda prompt. you need add 3 environment paths. like these: D:\Anaconda3; D:\Anaconda3\Scripts; D:\Anaconda3\Library\bin most people only add D:\Anaconda3\Scripts; For future Oracle Linux users trying to solve this, below is what worked for me. First install missing libs: yum install zlib

Python Tips and Tricks

蓝咒 提交于 2019-11-26 16:18:04
1. Install Python into Windows 1.1 Download Latest Python 2 file from https://www.python.org/downloads/windows/ Latest Python 3 Release – Python 3.7.0 Latest Python 2 Release – Python 2.7.15 1.2 Double Click download python-2.7.15.exe file to install it. 1.3 Run Python By Default, it will be installed at c:\Python27 folder C:\Users\John>cd \ C:\>cd Python27 C:\Python27> python --version Python 2.7.15 C:\Python27> python Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (In tel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 1.4

Run command and get its stdout, stderr separately in near real time like in a terminal

亡梦爱人 提交于 2019-11-26 11:50:58
I am trying to find a way in Python to run other programs in such a way that: The stdout and stderr of the program being run can be logged separately. The stdout and stderr of the program being run can be viewed in near-real time, such that if the child process hangs, the user can see. (i.e. we do not wait for execution to complete before printing the stdout/stderr to the user) Bonus criteria: The program being run does not know it is being run via python, and thus will not do unexpected things (like chunk its output instead of printing it in real-time, or exit because it demands a terminal to

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available

假如想象 提交于 2019-11-26 08:03:48
问题 I am using Python3.6, when i try to install \"modules\" using pip3, i am facing the below mentioned issue \"pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available\" Please help me to solve this issue 回答1: For Windows 10 if you want use pip in normal cmd, not only in Anaconda prompt. you need add 3 environment paths. like the followings: D:\Anaconda3; D:\Anaconda3\Scripts; D:\Anaconda3\Library\bin most people only add D:\Anaconda3\Scripts; 回答2: