MCPcopy Create free account
hub / github.com/pexpect/pexpect / setecho

Method setecho

pexpect/pty_spawn.py:382–414  ·  view source on GitHub ↗

This sets the terminal echo mode on or off. Note that anything the child sent before the echo will be lost, so you should be sure that your input buffer is empty before you call setecho(). For example, the following will work as expected:: p = pexpect.spawn('cat'

(self, state)

Source from the content-addressed store, hash-verified

380 return self.ptyproc.getecho()
381
382 def setecho(self, state):
383 '''This sets the terminal echo mode on or off. Note that anything the
384 child sent before the echo will be lost, so you should be sure that
385 your input buffer is empty before you call setecho(). For example, the
386 following will work as expected::
387
388 p = pexpect.spawn('cat') # Echo is on by default.
389 p.sendline('1234') # We expect see this twice from the child...
390 p.expect(['1234']) # ... once from the tty echo...
391 p.expect(['1234']) # ... and again from cat itself.
392 p.setecho(False) # Turn off tty echo
393 p.sendline('abcd') # We will set this only once (echoed by cat).
394 p.sendline('wxyz') # We will set this only once (echoed by cat)
395 p.expect(['abcd'])
396 p.expect(['wxyz'])
397
398 The following WILL NOT WORK because the lines sent before the setecho
399 will be lost::
400
401 p = pexpect.spawn('cat')
402 p.sendline('1234')
403 p.setecho(False) # Turn off tty echo
404 p.sendline('abcd') # We will set this only once (echoed by cat).
405 p.sendline('wxyz') # We will set this only once (echoed by cat)
406 p.expect(['1234'])
407 p.expect(['1234'])
408 p.expect(['abcd'])
409 p.expect(['wxyz'])
410
411
412 Not supported on platforms where ``isatty()`` returns False.
413 '''
414 return self.ptyproc.setecho(state)
415
416 def read_nonblocking(self, size=1, timeout=-1):
417 '''This reads at most size characters from the child application. It

Callers 5

__init__Method · 0.80
test_waitnoechoMethod · 0.80
_expect_echo_toggleMethod · 0.80

Calls

no outgoing calls

Tested by 4

test_waitnoechoMethod · 0.64
_expect_echo_toggleMethod · 0.64