-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtryPopenSpawn.py
44 lines (39 loc) · 1.06 KB
/
tryPopenSpawn.py
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
40
41
42
43
44
from pexpect.popen_spawn import PopenSpawn
import subprocess
import sys
import locale
import os
def _default_pexpect_kwargs():
encoding = 'utf-8'
if sys.platform == 'win32':
default_encoding = locale.getdefaultlocale()[1]
if default_encoding is not None:
encoding = default_encoding
return {
'env': os.environ.copy(),
'encoding': encoding,
'timeout': 30
}
_defualt_popen = _default_pexpect_kwargs().copy()
_defualt_popen['env']['PYTHONUNBUFFERED'] = '1'
try:
child = PopenSpawn('node')
print(child.read())
except:
print("Exception was thrown")
print("debug information:")
print(str(child))
# import pexpect
# child = pexpect.spawn('ftp ftp.openbsd.org')
# child.expect('Name .*: ')
# child.sendline('anonymous')
# child.expect('Password:')
# child.sendline('[email protected]')
# child.expect('ftp> ')
# child.sendline('lcd /tmp')
# child.expect('ftp> ')
# child.sendline('cd pub/OpenBSD')
# child.expect('ftp> ')
# child.sendline('get README')
# child.expect('ftp> ')
# child.sendline('bye')