forked from TEN-framework/ten-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
65 lines (53 loc) · 1.54 KB
/
Copy pathutils.py
File metadata and controls
65 lines (53 loc) · 1.54 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# Copyright © 2025 Agora
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import subprocess
import sys
import time
def run_cmd(cmd):
# print(cmd)
my_cmd = cmd
set_shell = True
if isinstance(cmd, list):
if sys.platform == "win32":
if cmd[0] != "cmd":
my_cmd = ["cmd", "/c"] + cmd
else:
set_shell = False
if isinstance(cmd, str):
if sys.platform == "win32" and cmd[:3] != "cmd":
my_cmd = "cmd /c " + cmd
child = subprocess.Popen(
my_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
shell=set_shell,
bufsize=0,
)
output = ""
while child.poll() is None:
line = ""
if child.stdout:
try:
line = child.stdout.readline()
except UnicodeDecodeError:
line = child.stdout.readline().encode("gbk")
if line != "":
output += str(line)
sys.stdout.flush()
sys.stdout.write("{}\n".format(line.rstrip()))
sys.stdout.flush()
return child.returncode, output
def run_cmd_with_retry(cmd: list[str], cnt: int = 10):
for i in range(1, cnt):
rc, output = run_cmd(cmd)
if rc == 0:
return rc, output
else:
time.sleep(1)
assert False
return []