File: monitor-e9

package info (click to toggle)
picolibc 1.8.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,184 kB
  • sloc: ansic: 281,743; asm: 24,643; python: 2,282; sh: 2,237; perl: 680; pascal: 329; exp: 287; makefile: 209; cpp: 72; xml: 40
file content (31 lines) | stat: -rwxr-xr-x 903 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3

import os
import sys
import subprocess

status = 1

with subprocess.Popen(sys.argv[1:], stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
    while True:
        status = proc.poll()
        if status:
            break;
        c = proc.stdout.read(1)
        if c == b'\xe9':
            line = proc.stdout.readline().decode('utf-8', errors='ignore')
            words = line.split()
            if len(words) > 0:
                if words[0] == 'exit':
                    proc.send_signal(1)
                    status = int(words[1])
                    if status >= 128:
                        status = status | 1
                    break
        sys.stdout.write(c.decode('utf-8', errors='ignore'))
    stderr = proc.stderr.read()
    for line in stderr.strip().split(b'\n'):
        if b'terminating on signal' not in line:
            print(line)

exit(status)