2018-04-19 00:30:05 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
# This script runs a process and prefixes its output with.
|
|
|
|
# Usage: run-and-prefix.py prefix command arg0 argv1...
|
|
|
|
|
2020-05-05 22:53:22 +03:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2018-04-19 00:30:05 +03:00
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2020-05-05 22:53:22 +03:00
|
|
|
sys.stdout = os.fdopen(sys.stdout.fileno(), "wb", 0)
|
|
|
|
sys.stderr = os.fdopen(sys.stderr.fileno(), "wb", 0)
|
2018-04-19 00:30:05 +03:00
|
|
|
|
2020-05-05 22:53:22 +03:00
|
|
|
prefix = sys.argv[1].encode("utf-8")
|
2018-04-19 00:30:05 +03:00
|
|
|
args = sys.argv[2:]
|
|
|
|
|
|
|
|
p = subprocess.Popen(
|
|
|
|
args,
|
|
|
|
bufsize=0,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
2020-07-28 00:51:13 +03:00
|
|
|
stdin=sys.stdin.fileno(),
|
|
|
|
close_fds=False,
|
|
|
|
)
|
2018-04-19 00:30:05 +03:00
|
|
|
|
|
|
|
while True:
|
|
|
|
data = p.stdout.readline()
|
|
|
|
|
|
|
|
if data == b"":
|
|
|
|
break
|
|
|
|
|
2020-05-05 22:53:22 +03:00
|
|
|
sys.stdout.write(b"%s> %s" % (prefix, data))
|
2018-04-19 00:30:05 +03:00
|
|
|
|
|
|
|
sys.exit(p.wait())
|