diff options
author | RafaĆ <23004737+rafrafek@users.noreply.github.com> | 2022-11-09 17:12:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-09 17:12:01 +0100 |
commit | 36bba631ac013b43cd892f5ce1499ee6ec8feecc (patch) | |
tree | 9aadb94cedda7f1826666e36d7add575b300923d | |
parent | acb017a97332c19a9295660fe87316926a8adc55 (diff) | |
download | pexpect-36bba631ac013b43cd892f5ce1499ee6ec8feecc.tar.gz |
Update docs to use context manager
Add an example to the docs of how to use spawn() function with context manager.
-rw-r--r-- | pexpect/__init__.py | 6 |
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. |