Giter Site home page Giter Site logo

Comments (7)

nmz787 avatar nmz787 commented on June 17, 2024

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.

nmz787 avatar nmz787 commented on June 17, 2024

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.

nmz787 avatar nmz787 commented on June 17, 2024

I'm not much of a Windows API expert, where should I start debugging this?

from wexpect.

nmz787 avatar nmz787 commented on June 17, 2024

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.

nmz787 avatar nmz787 commented on June 17, 2024

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.

raczben avatar raczben commented on June 17, 2024

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)
image

BUT

I've upgraded wexpect to 3.1.0
And, here is the wondow:
image

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.

raczben avatar raczben commented on June 17, 2024

Are your issue solved? If not please feel free to reopen this thread.

from wexpect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.