mirror of
https://github.com/clearml/wexpect-venv
synced 2025-01-31 02:46:59 +00:00
[ADD] examples
This commit is contained in:
parent
d6a8cc5e57
commit
2bd27dc77e
27
examples/cmd.py
Normal file
27
examples/cmd.py
Normal file
@ -0,0 +1,27 @@
|
||||
# A simple example code for wexpect written in python-2.7
|
||||
|
||||
from __future__ import print_function
|
||||
import wexpect
|
||||
|
||||
# Path of cmd executable:
|
||||
cmdPath = 'C:\Windows\System32\cmd.exe'
|
||||
cmdPrompt = '>'
|
||||
|
||||
# Start the child process
|
||||
p = wexpect.spawn(cmdPath)
|
||||
|
||||
# Wait for prompt
|
||||
p.expect(cmdPrompt)
|
||||
|
||||
# print the texts
|
||||
print(p.before, end='')
|
||||
print(p.match.group(0), end='')
|
||||
|
||||
# Send a command
|
||||
p.sendline('ls')
|
||||
p.expect(cmdPrompt)
|
||||
|
||||
# print the texts
|
||||
print(p.before, end='')
|
||||
print(p.match.group(0), end='')
|
||||
|
13
examples/foo.py
Normal file
13
examples/foo.py
Normal file
@ -0,0 +1,13 @@
|
||||
from __future__ import print_function
|
||||
import time
|
||||
|
||||
print('Give a small integer: ', end='')
|
||||
num = input()
|
||||
|
||||
for i in range(num):
|
||||
print('waiter ' + str(i))
|
||||
time.sleep(0.2)
|
||||
|
||||
print('Give your name: ', end='')
|
||||
name = raw_input()
|
||||
print('Hello ' + str(name), end='')
|
33
examples/python.py
Normal file
33
examples/python.py
Normal file
@ -0,0 +1,33 @@
|
||||
# A simple example code for wexpect written in python-2.7
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import wexpect
|
||||
|
||||
# Path of python executable:
|
||||
pythonInterp = sys.executable
|
||||
prompt = ': '
|
||||
|
||||
# Start the child process
|
||||
p = wexpect.spawn(pythonInterp, ['foo.py'])
|
||||
|
||||
# Wait for prompt
|
||||
p.expect(prompt)
|
||||
|
||||
# Send the 'small integer'
|
||||
p.sendline('3')
|
||||
p.expect(prompt)
|
||||
|
||||
# print the texts
|
||||
print(p.before, end='')
|
||||
print(p.match.group(0), end='')
|
||||
|
||||
# Send the name
|
||||
p.sendline('Bob')
|
||||
|
||||
# wait for program exit.
|
||||
p.wait()
|
||||
|
||||
# print the texts
|
||||
print(p.read(), end='')
|
||||
|
Loading…
Reference in New Issue
Block a user