-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathpython.py
More file actions
39 lines (29 loc) · 781 Bytes
/
Copy pathpython.py
File metadata and controls
39 lines (29 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''
This example script runs foo python program, and communicates with it. For better understanding
please run natively foo.py first, which is a very basic stdio handler script.
'''
import sys
import wexpect
import os
here = os.path.dirname(os.path.realpath(__file__))
# Path of python executable:
pythonInterp = sys.executable
prompt = ': '
# Start the child process
p = wexpect.spawn(pythonInterp, [here + '\\foo.py'])
# Wait for prompt
p.expect(prompt)
print(p.before)
# Send the 'small integer'
p.sendline('3')
p.expect(prompt)
print(p.before)
# 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='')