-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcapture_tee.py
More file actions
37 lines (31 loc) · 990 Bytes
/
Copy pathcapture_tee.py
File metadata and controls
37 lines (31 loc) · 990 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
from __future__ import print_function
import os
import subprocess
import sys
def run(cmd):
os.environ['PYTHONUNBUFFERED'] = "1"
proc = subprocess.Popen(cmd,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
universal_newlines = True,
)
stdout = []
stderr = []
mix = []
while proc.poll() is None:
line = proc.stdout.readline()
if line != "":
stdout.append(line)
mix.append(line)
print(line, end='')
line = proc.stderr.readline()
if line != "":
stderr.append(line)
mix.append(line)
print(line, end='')
return proc.returncode, stdout, stderr, mix
code, out, err, mix = run([sys.executable, 'examples/python/run.py'])
print("out: '{}'".format(out))
print("err: '{}'".format(err))
print("err: '{}'".format(mix))
print("exit: {}".format(code))