|
1 | 1 | # Pretend to ROOT that its input is a tty, to enable tab completion. |
2 | | -from __future__ import print_function |
3 | | -import pty, os, subprocess, sys, select |
| 2 | + |
| 3 | +import os |
| 4 | +import pty |
| 5 | +import select |
| 6 | +import subprocess |
| 7 | +import sys |
4 | 8 |
|
5 | 9 | # Create a tty: master is our side, slave is what we pass as Popen's stdin. |
6 | 10 | # This makes ROOT believe that its stdin is a tty. |
7 | 11 | master, slave = pty.openpty() |
8 | | -cmd = ['root.exe', '-b', '-l'] |
9 | | -proc = subprocess.Popen(cmd, |
10 | | - stdin = slave, |
11 | | - stdout = slave, |
12 | | - stderr = subprocess.PIPE, |
13 | | - close_fds=True |
14 | | - ) |
| 12 | +cmd = ["root.exe", "-b", "-l"] |
| 13 | +proc = subprocess.Popen(cmd, stdin=slave, stdout=slave, stderr=subprocess.PIPE, close_fds=True) |
15 | 14 |
|
16 | 15 | # Now we need to pass what's on our stdin to ROOT's stdin |
17 | 16 | # and read what's on the slave's stdout. |
18 | 17 | while True: |
19 | | - data = os.read(0, 1024); |
| 18 | + data = os.read(0, 1024) |
20 | 19 | if len(data) == 0: |
21 | 20 | break |
22 | | - #ret = master_stdin.write(data) |
| 21 | + # ret = master_stdin.write(data) |
23 | 22 | os.write(master, data) |
24 | | - while select.select([master],[],[],1.0)[0]: |
| 23 | + while select.select([master], [], [], 1.0)[0]: |
25 | 24 | os.write(1, os.read(master, 1)) |
26 | 25 |
|
27 | 26 | # Wait until the subprocess has exited... |
|
31 | 30 | out, err = proc.communicate() |
32 | 31 |
|
33 | 32 | # Then write the subprocess's output to our output streams. |
34 | | -#sys.stdout.write(out.decode('utf-8')) |
35 | | -sys.stderr.write(err.decode('utf-8')) |
| 33 | +# sys.stdout.write(out.decode('utf-8')) |
| 34 | +sys.stderr.write(err.decode("utf-8")) |
36 | 35 |
|
37 | 36 | # No need to wait; the subprocess is dead. |
38 | | -while select.select([master],[],[],0.0)[0]: |
39 | | - sys.stdout.write(os.read(master, 1).decode('utf-8')) |
| 37 | +while select.select([master], [], [], 0.0)[0]: |
| 38 | + sys.stdout.write(os.read(master, 1).decode("utf-8")) |
40 | 39 |
|
41 | 40 | exit(proc.returncode) |
42 | | - |
0 commit comments