Comments (7)
I wonder if it is some colored characters or something in the earlier console output... I'm finding that newlines just seem to fail after some point in my series of command executions
from wexpect.
Ok, here's a testcase. It wasn't caused by colored output.
I am running with py -3 testcase_main.py
When you comment out the first line of testcase.py then things work. Unfortunately I can't remove this import in my real-world usage.
You can uncomment the shell.interact()
and get the popup shell, and then press enter and the script will continue.
testcase.py
import readline # pip install pyreadline
# comment out the above import and all will be OK!!!
# unfortunately my real-world use-case is requiring that module, and removing it is out of my control
print("Your text")
print('back to normal now')
input("Run SVN Update?([yes]/no) : (assuming 'yes' in 1s-Press key to change.)")
print('WARNING! There are local changes un-committed:')
print(r' C:\Users\someone\git\test\blah\SOME_thing is missing!')
input('^^^ Press enter to acknowledge the above ^^^')
print('done!')
testcase_main.py
print("Your text")
import time
from wexpect import spawn
from wexpect import TIMEOUT, EOF
unique_prompt = '123123expect123123'
shell = spawn('cmd.exe')
time.sleep(1)
shell.sendline('PROMPT {}'.format(unique_prompt))
shell.expect(unique_prompt)
print('*** got cmd prompt')
shell.sendline('py -3 testcase.py')
DEBUG=False
i=0
always_break = False
while i!=1:
i = shell.expect([TIMEOUT,
unique_prompt,
u'Press ENTER to continue',
u"Run SVN Update\?\(\[yes\]\/no\)\s*: \(assuming 'yes' in 1s",
u'Run SVN Update\?\(\[yes\]\/no\)',
u'User for SVN:',
u'Password:',
u'Username:',
u'\^\^\^ Press enter to acknowledge the above \^\^\^'
], timeout=4)
print('expect gave I is : {}'.format(i))
if i == 2:
shell.sendline('\n')
elif (i == 4 or i==3):
shell.sendline(' yes') #note the leading space is required!!!
# shell.interact() # if you uncomment this line, you can press enter in the popup and it will continue
elif (i == 5 or i == 7):
shell.sendline(USERNAME)
elif i == 6:
shell.logfile_read = None # so we don't print the password during debug
shell.sendline(PASSWORD)
if DEBUG:
shell.logfile_read=log
elif i==8:
numbytes = shell.sendline()
print('numbytes from sendline was: {}'.format(numbytes))
elif i==9:
shell.sendline('\r\n')
print('*** finished expecting')
from wexpect.
I'm not much of a Windows API expert, where should I start debugging this?
from wexpect.
I have talked with some other people who work on the tools I am using wexpect to automate, and they said pyreadline
should not be required, so I think I am able to have a function which attempts to delete the installed module/package so it doesn't interfere with wexpect.
I am sure it would be good to figure out how to fix this properly though, as I guess other programs might cause a similar problem.
from wexpect.
I found if you replace the import readline
code in testcase.py
with this:
import sys
import mock
sys.modules['readline'] = mock.Mock()
then you I think you can get around later sub-module imports inside the same process.
from wexpect.
Sorry, for my passive behavior.
I've tried, and I could reproduce your issue.
I've added an interact()
call to see what happening in the console window. (Please add it for following tests)
...
shell = spawn('cmd.exe')
shell.interact() # <<<
time.sleep(1)
...
And, here is the wondow. (Using Python 3.7.5, virtualenv, wexpect<=3.0.0)
BUT
I've upgraded wexpect to 3.1.0
And, here is the wondow:
And the program finished succesfully.
(virt_i13) C:\Users\usr>python testcase_main.py
Your text
*** got cmd prompt
expect gave I is : 1
*** finished expecting
Please upgrade wexpect to 3.1.0, or higher. Note, that wexpect is not a one-file module anymore. You need to install it.
from wexpect.
Are your issue solved? If not please feel free to reopen this thread.
from wexpect.
Related Issues (20)
- logger crashes at the end of the program HOT 6
- spawn problems on Windows 10 HOT 4
- Windows 10 wexpect.spawn('telnet') doesn't seem to work HOT 3
- How to get the matching print? HOT 1
- Always TIMEOUT HOT 3
- always get Error: no spawn class: {spawn_class_name} when import wexpect HOT 1
- Fix hello_wexpect HOT 2
- Can't work with windows's ssh client? HOT 1
- Asyncio support
- wexpect throw UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position 2999: unexpected end of data HOT 1
- Regex in expect fail in W10 and Python 3.9 HOT 2
- spawn hangs when run in virtual environment HOT 4
- Critical Performance Issue HOT 2
- pywintypes.error: (2, 'CreateFile', '系统找不到指定的文件') HOT 1
- logfile parameter not working in version 4.0.0 HOT 1
- Port overload when running multiple instances leads to timeout
- Stuck in loop trying to initialize pipe HOT 3
- Update testcases to work for Windows + write them in pytest
- command_with_path = shutil.which(self.command) breaks Windows command support
- Function of sendeof in Windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wexpect.