summaryrefslogtreecommitdiff
path: root/pexpect/__init__.py
diff options
context:
space:
mode:
authorRed_M <1468433+Red-M@users.noreply.github.com>2023-04-03 02:04:42 +1000
committerGitHub <noreply@github.com>2023-04-03 02:04:42 +1000
commit06f4ed2be13b9209d1ac89c72bf4a19d550cc846 (patch)
tree194d3359665bbb6d71a767a30750966ad2e69f61 /pexpect/__init__.py
parentdd3cc5c8ea71e1400f0e21fbcc3749c49af5362b (diff)
parent36bba631ac013b43cd892f5ce1499ee6ec8feecc (diff)
downloadpexpect-06f4ed2be13b9209d1ac89c72bf4a19d550cc846.tar.gz
Merge pull request #728 from rafrafek/patch-1
Update docs to use context manager
Diffstat (limited to 'pexpect/__init__.py')
-rw-r--r--pexpect/__init__.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/pexpect/__init__.py b/pexpect/__init__.py
index b3a64b6..1c6bdb7 100644
--- a/pexpect/__init__.py
+++ b/pexpect/__init__.py
@@ -29,6 +29,12 @@ For example::
child.expect('Password:')
child.sendline(mypassword)
+Context manager can be used for the spawn() function::
+
+ with pexpect.spawn('scp foo user@example.com:.') as child:
+ child.expect('Password:')
+ child.sendline(mypassword)
+
This works even for commands that ask for passwords or other input outside of
the normal stdio streams. For example, ssh reads input directly from the TTY
device which bypasses stdin.