MCPcopy Create free account
hub / github.com/XiaoMi/mace / execute

Function execute

tools/python/utils/device.py:29–66  ·  view source on GitHub ↗
(cmd, verbose=True)

Source from the content-addressed store, hash-verified

27
28
29def execute(cmd, verbose=True):
30 if verbose:
31 print("CMD> %s" % cmd)
32 p = subprocess.Popen([cmd],
33 shell=True,
34 stdout=subprocess.PIPE,
35 stderr=subprocess.STDOUT,
36 stdin=subprocess.PIPE,
37 universal_newlines=True)
38
39 if not verbose:
40 # use p.communicate instead of p.wait to avoid such situation:
41 # pipe is filled and the child process is blocked.
42 out, err = p.communicate()
43 if p.returncode != 0:
44 raise Exception("errorcode: {}".format(p.returncode))
45 return out
46
47 buf = []
48
49 while p.poll() is None:
50 line = p.stdout.readline().strip()
51 if verbose:
52 print(line)
53 buf.append(line)
54
55 for li in p.stdout:
56 line = li.strip()
57 if verbose:
58 print(line)
59 buf.append(line)
60
61 if p.returncode != 0:
62 if verbose:
63 print(line)
64 raise Exception("errorcode: %s" % p.returncode)
65
66 return "\n".join(buf)
67
68
69class Device(object):

Callers 15

installMethod · 0.85
runMethod · 0.85
pullMethod · 0.85
mkdirMethod · 0.85
list_devicesMethod · 0.85
installMethod · 0.85
runMethod · 0.85
pullMethod · 0.85
mkdirMethod · 0.85
infoMethod · 0.85
installMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected