diff --git a/examples/cmd.py b/examples/cmd.py new file mode 100644 index 0000000..4b76552 --- /dev/null +++ b/examples/cmd.py @@ -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='') + diff --git a/examples/foo.py b/examples/foo.py new file mode 100644 index 0000000..997f451 --- /dev/null +++ b/examples/foo.py @@ -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='') \ No newline at end of file diff --git a/examples/python.py b/examples/python.py new file mode 100644 index 0000000..94597c1 --- /dev/null +++ b/examples/python.py @@ -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='') +